passwordAuthenticationMethod:resetPassword
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
为与密码身份验证方法对象关联的 密码启动重置 。 这只能由具有适当权限的管理员完成,并且不能对用户自己的帐户执行。
此流将新密码写入Azure Active Directory,如果已使用密码写回本地 Active Directory则推送到新密码。 管理员可以提供新密码或使系统生成一个密码。 系统将提示用户在下次登录时更改其密码。
此重置是一项长时间运行的操作,它将返回一个 Location 标头,其中具有一个链接,调用方可以在其中定期检查重置操作的状态。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
重要
不能在用户自己的帐户上执行该操作。 只有具有适当权限的管理员才能执行此操作。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
UserAuthenticationMethod.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
不支持。
对于管理员正在操作其他用户的委派方案,管理员需要以下角色Azure AD之一 :
HTTP 请求
POST /users/{id | userPrincipalName}/authentication/passwordMethods/{id}/resetPassword
名称
说明
Authorization
Bearer {token}。必需。
Content-type
application/json. Required.
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
参数
类型
说明
newPassword
String
新密码。 对于具有混合密码方案的租户,此为必需项。 如果省略仅云密码,系统将返回系统生成的密码。 这是一个没有其他编码的 unicode 字符串。 在验收之前,将针对租户的禁止密码系统验证它,并且必须遵守租户的云和/或本地密码要求。
响应
如果成功,此方法返回 响应 202 Accepted 代码和 包含 URL 的位置 标头,以检查重置操作的状态。
如果调用方未提交密码,则响应正文中的 JSON 对象中会提供 Microsoft 生成的密码。
名称
说明
Location
要调用以检查操作状态的 URL。 必需。
重试后
持续时间(以秒表示)。 可选。
示例
示例 1:用户提交的密码
以下示例显示当调用方提交密码时如何调用此 API。
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword
Content-type: application/json
{
"newPassword": "Cuyo5459"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var newPassword = "Cuyo5459";
await graphClient.Users["{user-id}"].Authentication.PasswordMethods["{passwordAuthenticationMethod-id}"]
.ResetPassword(newPassword,null)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
const passwordResetResponse = {
newPassword: 'Cuyo5459'
};
await client.api('/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword')
.version('beta')
.post(passwordResetResponse);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSString *newPassword = @"Cuyo5459";
payloadDictionary[@"newPassword"] = newPassword;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
String newPassword = "Cuyo5459";
graphClient.users("6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0").authentication().passwordMethods("28c10230-6103-485e-b985-444c60001490")
.resetPassword(AuthenticationMethodResetPasswordParameterSet
.newBuilder()
.withNewPassword(newPassword)
.withRequireChangeOnNextSignIn(null)
.build())
.buildRequest()
.post();
响应
下面展示了示例响应。
HTTP/1.1 202 Accepted
Content-type: application/json
Location: https://graph.microsoft.com/beta/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/operations/88e7560c-9ebf-435c-8089-c3998ac1ec51?aadgdc=DUB02P&aadgsu=ssprprod-a
{}
示例 2:系统生成的密码
以下示例演示当调用方不提交密码时如何调用此 API。
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
await graphClient.Users["{user-id}"].Authentication.PasswordMethods["{passwordAuthenticationMethod-id}"]
.ResetPassword(null,null)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
await client.api('/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword')
.version('beta')
.post();
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword"]]];
[urlRequest setHTTPMethod:@"POST"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
graphClient.users("6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0").authentication().passwordMethods("28c10230-6103-485e-b985-444c60001490")
.resetPassword(AuthenticationMethodResetPasswordParameterSet
.newBuilder()
.withNewPassword(null)
.withRequireChangeOnNextSignIn(null)
.build())
.buildRequest()
.post();
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 202 ACCEPTED
Location: https://graph.microsoft.com/beta/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/operations/77bafe36-3ac0-4f89-96e4-a4a5a48da851?aadgdc=DUB02P&aadgsu=ssprprod-a
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.passwordResetResponse",
"newPassword": "Cuyo5459"
}