命名空间:microsoft.graph
重置用户的密码,由 密码身份验证方法 对象表示。 这只能由具有适当权限的管理员完成,不能在用户自己的帐户上执行。
若要在 Azure AD B2C 中重置用户密码,请使用 更新用户 API 操作并更新 passwordProfile>forceChangePasswordNextSignIn 对象。
此流将新密码写入Microsoft Entra ID,并将其推送到本地 Active Directory(如果使用密码写回进行配置)。 管理员可以提供新密码,也可以让系统生成一个新密码。 系统会提示用户在下次登录时更改其密码。
此重置是一个长时间运行的操作,并返回一个 Location 标头,其中包含一个链接,调用方可以在该链接中定期检查重置操作的状态。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
❌ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
UserAuthenticationMethod.ReadWrite.All |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
不支持。 |
不支持。 |
具有 用户管理员、 支持管理员或 密码管理员 角色的管理员还可以重置非管理员用户的密码和一组有限的管理员角色,如 谁可以重置密码中定义。
HTTP 请求
引用 {passwordMethods-id}
的密码身份验证方法的 ID 始终 28c10230-6103-485e-b985-444c60001490
为 。
POST /users/{id | userPrincipalName}/authentication/methods/{passwordMethods-id}/resetPassword
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-type |
application/json. 必需。 |
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
参数 |
类型 |
说明 |
newPassword |
String |
新密码。 对于具有混合密码方案的租户,是必需的。 如果省略仅限云的密码,系统将返回系统生成的密码。 这是一个没有其他编码的 unicode 字符串。 在接受之前,它已针对租户的禁止密码系统进行验证,并且必须遵守租户的云和/或本地密码要求。 |
响应
如果调用方在请求正文中提供了密码,则此方法返回 202 Accepted
响应代码,且不返回响应正文。 响应可能还包括一个 Location 标头,其中包含用于检查重置操作状态的 URL。
如果调用方使用系统生成的密码选项,则此方法在响应正文中返回 202 Accepted
响应代码和 passwordResetResponse 对象,其中包含Microsoft生成的密码。 响应可能还包括一个 Location 标头,其中包含用于检查重置操作状态的 URL。
名称 |
说明 |
位置 |
用于调用的 URL,检查操作的状态。 必填。 |
重试后 |
持续时间(以秒为单位)。 可选。 |
示例
示例 1:用户提交的密码
以下示例演示如何在调用方提交密码时调用此 API。
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/methods/28c10230-6103-485e-b985-444c60001490/resetPassword
Content-type: application/json
{
"newPassword": "Cuyo5459"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Users.Item.Authentication.Methods.Item.ResetPassword;
var requestBody = new ResetPasswordPostRequestBody
{
NewPassword = "Cuyo5459",
};
// 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.Methods["{authenticationMethod-id}"].ResetPassword.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc users authentication methods reset-password post --user-id {user-id} --authentication-method-id {authenticationMethod-id} --body '{\
"newPassword": "Cuyo5459"\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
//other-imports
)
requestBody := graphusers.NewResetPasswordPostRequestBody()
newPassword := "Cuyo5459"
requestBody.SetNewPassword(&newPassword)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
resetPassword, err := graphClient.Users().ByUserId("user-id").Authentication().Methods().ByAuthenticationMethodId("authenticationMethod-id").ResetPassword().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.users.item.authentication.methods.item.resetpassword.ResetPasswordPostRequestBody resetPasswordPostRequestBody = new com.microsoft.graph.users.item.authentication.methods.item.resetpassword.ResetPasswordPostRequestBody();
resetPasswordPostRequestBody.setNewPassword("Cuyo5459");
var result = graphClient.users().byUserId("{user-id}").authentication().methods().byAuthenticationMethodId("{authenticationMethod-id}").resetPassword().post(resetPasswordPostRequestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const passwordResetResponse = {
newPassword: 'Cuyo5459'
};
await client.api('/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/methods/28c10230-6103-485e-b985-444c60001490/resetPassword')
.post(passwordResetResponse);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Users\Item\Authentication\Methods\Item\ResetPassword\ResetPasswordPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ResetPasswordPostRequestBody();
$requestBody->setNewPassword('Cuyo5459');
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->methods()->byAuthenticationMethodId('authenticationMethod-id')->resetPassword()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Identity.SignIns
$params = @{
newPassword = "Cuyo5459"
}
Reset-MgUserAuthenticationMethodPassword -UserId $userId -AuthenticationMethodId $authenticationMethodId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.users.item.authentication.methods.item.reset_password.reset_password_post_request_body import ResetPasswordPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ResetPasswordPostRequestBody(
new_password = "Cuyo5459",
)
result = await graph_client.users.by_user_id('user-id').authentication.methods.by_authentication_method_id('authenticationMethod-id').reset_password.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Content-type: application/json
Location: https://graph.microsoft.com/v1.0/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/v1.0/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/methods/28c10230-6103-485e-b985-444c60001490/resetPassword
{
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Users.Item.Authentication.Methods.Item.ResetPassword;
var requestBody = new ResetPasswordPostRequestBody
{
};
// 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.Methods["{authenticationMethod-id}"].ResetPassword.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc users authentication methods reset-password post --user-id {user-id} --authentication-method-id {authenticationMethod-id}
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
//other-imports
)
requestBody := graphusers.NewResetPasswordPostRequestBody()
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
resetPassword, err := graphClient.Users().ByUserId("user-id").Authentication().Methods().ByAuthenticationMethodId("authenticationMethod-id").ResetPassword().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.users.item.authentication.methods.item.resetpassword.ResetPasswordPostRequestBody resetPasswordPostRequestBody = new com.microsoft.graph.users.item.authentication.methods.item.resetpassword.ResetPasswordPostRequestBody();
var result = graphClient.users().byUserId("{user-id}").authentication().methods().byAuthenticationMethodId("{authenticationMethod-id}").resetPassword().post(resetPasswordPostRequestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const passwordResetResponse = {
};
await client.api('/users/6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0/authentication/methods/28c10230-6103-485e-b985-444c60001490/resetPassword')
.post(passwordResetResponse);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Users\Item\Authentication\Methods\Item\ResetPassword\ResetPasswordPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ResetPasswordPostRequestBody();
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->methods()->byAuthenticationMethodId('authenticationMethod-id')->resetPassword()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Identity.SignIns
$params = @{
}
Reset-MgUserAuthenticationMethodPassword -UserId $userId -AuthenticationMethodId $authenticationMethodId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.users.item.authentication.methods.item.reset_password.reset_password_post_request_body import ResetPasswordPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ResetPasswordPostRequestBody(
)
result = await graph_client.users.by_user_id('user-id').authentication.methods.by_authentication_method_id('authenticationMethod-id').reset_password.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。 可以使用 Location 标头中的 ID 通过长时间运行的操作 API 检查操作的状态。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 202 Accepted
Location: https://graph.microsoft.com/v1.0/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/v1.0/$metadata#microsoft.graph.passwordResetResponse",
"newPassword": "Cuyo5459"
}