Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Update the properties of a user's authentication method states. Use this API to update the following information:
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permissions to update system-preferred MFA
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
Important
In delegated scenarios with work or school accounts where the signed-in user is acting on another user, they must be assigned a supported Microsoft Entra role or a custom role with a supported role permission. The following least privileged roles are supported for this operation.
- Authentication Administrator
- Privileged Authentication Administrator
Permissions to update per-user MFA state
Permissions acting on self
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Policy.ReadWrite.AuthenticationMethod |
Not available. |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
Not supported. |
Not supported. |
Permissions acting on others
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Policy.ReadWrite.AuthenticationMethod |
Not available. |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
Policy.ReadWrite.AuthenticationMethod |
Not available. |
Important
In delegated scenarios with work or school accounts, the signed-in user must be assigned a supported Microsoft Entra role or a custom role with a supported role permission. Authentication Policy Administrator is the least privileged role supported for this operation.
HTTP request
To update the sign-in preferences (system-preferred MFA) for a user:
PATCH /users/{id | userPrincipalName}/authentication/signInPreferences
To update the per-user multifactor authentication state for the signed-in user:
PATCH /me/authentication/requirements
Note
Calling the /me
endpoint requires a signed-in user and therefore a delegated permission. Application permissions aren't supported when using the /me
endpoint.
To update the per-user multifactor authentication state for a user:
PATCH /users/{id | userPrincipalName}/authentication/requirements
Request body
In the request body, supply only the values for properties to update. Existing properties that aren't included in the request body maintain their previous values or are recalculated based on changes to other property values.
The following table specifies the properties that can be updated.
Property |
Type |
Description |
isSystemPreferredAuthenticationMethodEnabled |
Boolean |
Indicates whether the credential preferences of the system are enabled. |
userPreferredMethodForSecondaryAuthentication |
userDefaultAuthenticationMethodType |
The default second-factor method used by the user when signing in. If a user is enabled for system-preferred authentication, then this value is ignored except for a few scenarios where a user is authenticating via NPS extension or ADFS adapter. Possible values are push , oath , voiceMobile , voiceAlternateMobile , voiceOffice , sms , and unknownFutureValue |
perUserMfaState |
perUserMfaState |
The user's state for per-user multifactor authentication. Possible values are enforced , enabled and disabled . |
Response
If successful, this method returns a 204 No Content
response code.
Examples
Example 1: Update a user's system-preferred MFA method
Request
The following example shows a request.
PATCH https://graph.microsoft.com/beta/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/signInPreferences
Content-Type: application/json
{
"userPreferredMethodForSecondaryAuthentication": "oath"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new SignInPreferences
{
UserPreferredMethodForSecondaryAuthentication = UserDefaultAuthenticationMethodType.Oath,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].Authentication.SignInPreferences.PatchAsync(requestBody);
mgc-beta users authentication sign-in-preferences patch --user-id {user-id} --body '{\
"userPreferredMethodForSecondaryAuthentication": "oath"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewSignInPreferences()
userPreferredMethodForSecondaryAuthentication := graphmodels.OATH_USERDEFAULTAUTHENTICATIONMETHODTYPE
requestBody.SetUserPreferredMethodForSecondaryAuthentication(&userPreferredMethodForSecondaryAuthentication)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
signInPreferences, err := graphClient.Users().ByUserId("user-id").Authentication().SignInPreferences().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SignInPreferences signInPreferences = new SignInPreferences();
signInPreferences.setUserPreferredMethodForSecondaryAuthentication(UserDefaultAuthenticationMethodType.Oath);
SignInPreferences result = graphClient.users().byUserId("{user-id}").authentication().signInPreferences().patch(signInPreferences);
const options = {
authProvider,
};
const client = Client.init(options);
const signInPreferences = {
userPreferredMethodForSecondaryAuthentication: 'oath'
};
await client.api('/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/signInPreferences')
.version('beta')
.update(signInPreferences);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\SignInPreferences;
use Microsoft\Graph\Beta\Generated\Models\UserDefaultAuthenticationMethodType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SignInPreferences();
$requestBody->setUserPreferredMethodForSecondaryAuthentication(new UserDefaultAuthenticationMethodType('oath'));
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->signInPreferences()->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.SignIns
$params = @{
userPreferredMethodForSecondaryAuthentication = "oath"
}
Update-MgBetaUserAuthenticationSignInPreference -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.sign_in_preferences import SignInPreferences
from msgraph_beta.generated.models.user_default_authentication_method_type import UserDefaultAuthenticationMethodType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SignInPreferences(
user_preferred_method_for_secondary_authentication = UserDefaultAuthenticationMethodType.Oath,
)
result = await graph_client.users.by_user_id('user-id').authentication.sign_in_preferences.patch(request_body)
Response
HTTP/1.1 204 No Content
Example 2: Update a user's MFA state
Request
The following example shows a request.
PATCH https://graph.microsoft.com/beta/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/requirements
Content-Type: application/json
{
"perUserMfaState": "disabled"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new StrongAuthenticationRequirements
{
PerUserMfaState = PerUserMfaState.Disabled,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].Authentication.Requirements.PatchAsync(requestBody);
mgc-beta users authentication requirements patch --user-id {user-id} --body '{\
"perUserMfaState": "disabled"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewStrongAuthenticationRequirements()
perUserMfaState := graphmodels.DISABLED_PERUSERMFASTATE
requestBody.SetPerUserMfaState(&perUserMfaState)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
requirements, err := graphClient.Users().ByUserId("user-id").Authentication().Requirements().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
StrongAuthenticationRequirements strongAuthenticationRequirements = new StrongAuthenticationRequirements();
strongAuthenticationRequirements.setPerUserMfaState(PerUserMfaState.Disabled);
StrongAuthenticationRequirements result = graphClient.users().byUserId("{user-id}").authentication().requirements().patch(strongAuthenticationRequirements);
const options = {
authProvider,
};
const client = Client.init(options);
const strongAuthenticationRequirements = {
perUserMfaState: 'disabled'
};
await client.api('/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/requirements')
.version('beta')
.update(strongAuthenticationRequirements);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\StrongAuthenticationRequirements;
use Microsoft\Graph\Beta\Generated\Models\PerUserMfaState;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new StrongAuthenticationRequirements();
$requestBody->setPerUserMfaState(new PerUserMfaState('disabled'));
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->requirements()->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.SignIns
$params = @{
perUserMfaState = "disabled"
}
Update-MgBetaUserAuthenticationRequirement -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.strong_authentication_requirements import StrongAuthenticationRequirements
from msgraph_beta.generated.models.per_user_mfa_state import PerUserMfaState
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = StrongAuthenticationRequirements(
per_user_mfa_state = PerUserMfaState.Disabled,
)
result = await graph_client.users.by_user_id('user-id').authentication.requirements.patch(request_body)
Response
HTTP/1.1 204 No Content