命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新用户的身份验证方法状态的属性。 使用此 API 更新以下信息:
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
更新系统首选 MFA 的权限
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
重要
在具有工作或学校帐户的委托方案中,如果已登录用户对其他用户进行作,则必须为他们分配受支持的Microsoft Entra角色或具有受支持角色权限的自定义角色。 此作支持以下最低特权角色。
更新每用户 MFA 状态的权限
针对自身作的权限
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Policy.ReadWrite.AuthenticationMethod |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
不支持。 |
不支持。 |
对其他人进行作的权限
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Policy.ReadWrite.AuthenticationMethod |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Policy.ReadWrite.AuthenticationMethod |
不可用。 |
重要
在具有工作或学校帐户的委托方案中,必须为登录用户分配受支持的Microsoft Entra角色或具有支持的角色权限的自定义角色。
身份验证策略管理员 是此作支持的最低特权角色。
HTTP 请求
若要为用户更新登录首选项 (系统首选 MFA) ,请执行以下作:
PATCH /users/{id | userPrincipalName}/authentication/signInPreferences
若要更新已登录用户的按用户多重身份验证状态,请执行以下作:
PATCH /me/authentication/requirements
注意
调用 /me
终结点需要已登录的用户,因此需要委派权限。 使用 /me
终结点时,不支持应用程序权限。
若要更新用户的按用户多重身份验证状态,请执行以下作:
PATCH /users/{id | userPrincipalName}/authentication/requirements
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
application/json. 必需。 |
请求正文
在请求正文中, 仅 提供要更新的属性的值。 请求正文中未包含的现有属性会保留其以前的值,或者根据对其他属性值的更改重新计算。
下表指定可更新的属性。
属性 |
类型 |
说明 |
isSystemPreferredAuthenticationMethodEnabled |
布尔值 |
指示是否启用系统的凭据首选项。 |
userPreferredMethodForSecondaryAuthentication |
userDefaultAuthenticationMethodType |
用户登录时使用的默认第二因素方法。 如果用户启用了系统首选身份验证,则忽略此值,但用户通过 NPS 扩展或 ADFS 适配器进行身份验证的少数方案除外。 可能的值为 push 、、oath 、voiceMobile 、voiceAlternateMobile voiceOffice 、 sms 和unknownFutureValue |
perUserMfaState |
perUserMfaState |
每用户多重身份验证的用户状态。 可能的值为 enforced 、 enabled 和 disabled 。 |
响应
如果成功,此方法返回 204 No Content
响应代码。
示例
示例 1:更新用户的系统首选 MFA 方法
请求
以下示例显示了一个请求。
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)
响应
HTTP/1.1 204 No Content
示例 2:更新用户的 MFA 状态
请求
以下示例显示了一个请求。
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)
响应
HTTP/1.1 204 No Content