更新 phoneAuthenticationMethod
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新与电话身份验证方法 关联的电话号码。
你无法更改电话的类型。 若要更改电话的类型,请添加所需类型的新号码,然后删除具有原始类型的对象。
如果策略允许用户使用短信登录并更改号码,系统将尝试注册用于 mobile 该系统的号码。
Permissions
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
自行操作的权限
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
UserAuthenticationMethod.ReadWrite |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| Application |
不支持。 |
对其他用户操作的权限
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
UserAuthenticationMethod.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| Application |
UserAuthenticationMethod.ReadWrite.All |
对于管理员在另一用户上操作的委派方案,管理员需要以下角色Azure AD之一:
HTTP 请求
PUT /me/authentication/phoneMethods/{id}
PUT /users/{id | userPrincipalName}/authentication/phoneMethods/{id}
与要 id 更新的 phoneType 对应的值是下列值之一:
b6332ec1-7057-4abe-9331-3d72feddfe41 更新 alternateMobile phoneType。
e37fc753-ff3b-4958-9484-eaa9425c82bc 更新 office phoneType。
3179e48a-750b-4051-897c-87b9720928f7 更新 mobile phoneType。
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-type |
application/json. Required. |
请求正文
在请求正文中,提供应更新的相关字段的值。 请求正文中未包含的现有属性将基于其他属性值的更改重新计算。
| 属性 |
类型 |
说明 |
| phoneNumber |
String |
要发送文本或呼叫进行身份验证的电话号码。 电话数字使用格式"+ <country code> <number>x <extension> ",扩展是可选的。 例如,+1 5555551234 +1 555551234x123 有效。 如果数字与所需格式不匹配,则创建/更新时将拒绝数字。 |
| phoneType |
string |
可能的值为: mobile、 alternateMobile或 office。 |
响应
如果成功,此方法在响应正文中返回 响应代码和更新的 200 OK phoneAuthenticationMethod 对象。
示例
请求
下面展示了示例请求。
PUT https://graph.microsoft.com/beta/me/authentication/phoneMethods/3179e48a-750b-4051-897c-87b9720928f7
Content-type: application/json
{
"phoneNumber": "+1 2065555554",
"phoneType": "mobile",
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var phoneAuthenticationMethod = new PhoneAuthenticationMethod
{
PhoneNumber = "+1 2065555554",
PhoneType = AuthenticationPhoneType.Mobile
};
await graphClient.Me.Authentication.PhoneMethods["{phoneAuthenticationMethod-id}"]
.Request()
.PutAsync(phoneAuthenticationMethod);
const options = {
authProvider,
};
const client = Client.init(options);
const phoneAuthenticationMethod = {
phoneNumber: '+1 2065555554',
phoneType: 'mobile',
};
await client.api('/me/authentication/phoneMethods/3179e48a-750b-4051-897c-87b9720928f7')
.version('beta')
.put(phoneAuthenticationMethod);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/authentication/phoneMethods/3179e48a-750b-4051-897c-87b9720928f7"]]];
[urlRequest setHTTPMethod:@"PUT"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphPhoneAuthenticationMethod *phoneAuthenticationMethod = [[MSGraphPhoneAuthenticationMethod alloc] init];
[phoneAuthenticationMethod setPhoneNumber:@"+1 2065555554"];
[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 2065555554";
phoneAuthenticationMethod.phoneType = AuthenticationPhoneType.MOBILE;
graphClient.me().authentication().phoneMethods("3179e48a-750b-4051-897c-87b9720928f7")
.buildRequest()
.put(phoneAuthenticationMethod);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
requestBody.SetAdditionalData(map[string]interface{}{
"phoneNumber": "+1 2065555554",
"phoneType": "mobile",
}
phoneAuthenticationMethodId := "phoneAuthenticationMethod-id"
graphClient.Me().Authentication().PhoneMethodsById(&phoneAuthenticationMethodId).Put(requestBody)
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"phoneNumber": "+1 2065555554",
"phoneType": "mobile",
"smsSignInState": "ready",
"id": "3179e48a-750b-4051-897c-87b9720928f7"
}