创建 phoneAuthenticationMethod
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
添加新的电话 身份验证方法 。 用户只能有一部每种电话,在 phoneType 属性中捕获。 这意味着,向具有预先不存在的电话的用户添加电话 mobile mobile 将失败。 此外,在添加电话之前, mobile 用户必须始终拥有 alternateMobile 电话。
通过添加电话号码,可以同时在 Azure 多重身份验证 (MFA) 和自助服务密码重置 (SSPR) (如果已启用)。
此外,如果策略允许用户使用短信登录并添加号码,系统将尝试注册号码以 mobile 在该系统中使用该号码。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
自行操作的权限
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
UserAuthenticationMethod.ReadWrite
委派(个人 Microsoft 帐户)
不支持。
应用程序
不支持。
对其他用户操作的权限
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
UserAuthenticationMethod.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
UserAuthenticationMethod.ReadWrite.All
对于管理员正在操作其他用户的委派方案,管理员需要以下角色Azure AD之一 :
HTTP 请求
POST /me/authentication/phoneMethods
POST /users/{id | userPrincipalName}/authentication/phoneMethods
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供 phoneAuthenticationMethod 对象的 JSON 表示形式。 JSON 必须包括 phoneNumber phoneType 和 smsSignInState , (,这是只读的) 。
属性
类型
Description
phoneNumber
String
要发送文本或呼叫进行身份验证的电话号码。 电话数字使用格式"+ <country code> <number>x <extension> ",扩展是可选的。 例如,+1 5555551234 +1 555551234x123 有效。 如果数字与所需格式不匹配,则创建/更新时将拒绝数字。
phoneType
String
可能的值是 mobile :、 alternateMobile 和 office 。
响应
如果成功,此方法在响应正文中返回 响应代码和新 201 Created phoneAuthenticationMethod 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/me/authentication/phoneMethods
Content-type: application/json
{
"phoneNumber": "+1 2065555555",
"phoneType": "mobile"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var phoneAuthenticationMethod = new PhoneAuthenticationMethod
{
PhoneNumber = "+1 2065555555",
PhoneType = AuthenticationPhoneType.Mobile
};
await graphClient.Me.Authentication.PhoneMethods
.Request()
.AddAsync(phoneAuthenticationMethod);
const options = {
authProvider,
};
const client = Client.init(options);
const phoneAuthenticationMethod = {
phoneNumber: '+1 2065555555',
phoneType: 'mobile'
};
await client.api('/me/authentication/phoneMethods')
.version('beta')
.post(phoneAuthenticationMethod);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/authentication/phoneMethods"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphPhoneAuthenticationMethod *phoneAuthenticationMethod = [[MSGraphPhoneAuthenticationMethod alloc] init];
[phoneAuthenticationMethod setPhoneNumber:@"+1 2065555555"];
[phoneAuthenticationMethod setPhoneType: [MSGraphAuthenticationPhoneType mobile]];
NSError *error;
NSData *phoneAuthenticationMethodData = [phoneAuthenticationMethod getSerializedDataWithError:&error];
[urlRequest setHTTPBody:phoneAuthenticationMethodData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
PhoneAuthenticationMethod phoneAuthenticationMethod = new PhoneAuthenticationMethod();
phoneAuthenticationMethod.phoneNumber = "+1 2065555555";
phoneAuthenticationMethod.phoneType = AuthenticationPhoneType.MOBILE;
graphClient.me().authentication().phoneMethods()
.buildRequest()
.post(phoneAuthenticationMethod);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewPhoneAuthenticationMethod()
phoneNumber := "+1 2065555555"
requestBody.SetPhoneNumber(&phoneNumber)
phoneType := "mobile"
requestBody.SetPhoneType(&phoneType)
result, err := graphClient.Me().Authentication().PhoneMethods().Post(requestBody)
Import-Module Microsoft.Graph.Identity.SignIns
$params = @{
PhoneNumber = "+1 2065555555"
PhoneType = "mobile"
}
# A UPN can also be used as -UserId.
New-MgUserAuthenticationPhoneMethod -UserId $userId -BodyParameter $params
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"phoneNumber": "+1 2065555555",
"phoneType": "phoneType-value",
"smsSignInState": "ready",
"id": "3179e48a-750b-4051-897c-87b9720928f7"
}