application: addPassword
命名空间:microsoft.graph
向应用程序添加强 密码。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Application.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
Application.ReadWrite.All |
| 应用程序 |
Application.ReadWrite.OwnedBy、Application.ReadWrite.All、Directory.Read.All |
HTTP 请求
POST /applications/{id}/addPassword
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供具有以下 passwordCredential 属性的可选对象。
| 属性 |
类型 |
说明 |
| displayName |
String |
密码的友好名称。 可选。 |
| endDateTime |
DateTimeOffset |
密码过期的日期和时间使用 ISO 8601 格式表示,并且始终处于 UTC 时间。 例如,2014 年 1 月 1 日午夜 UTC 为 2014-01-01T00:00:00Z。 可选。 默认值为"startDateTime + 2 年"。 |
| startDateTime |
DateTimeOffset |
密码生效的日期和时间。 时间戳类型表示采用 ISO 8601 格式的日期和时间信息,始终采用 UTC 时区。 例如,2014 年 1 月 1 日午夜 UTC 为 2014-01-01T00:00:00Z。 可选。 默认值为"now"。 |
响应
如果成功,此方法在响应 200 OK 正文中返回 响应代码和新 passwordCredential 对象。 响应 对象中的 secretText 属性包含由 Azure Active Directory生成的强密码,长度为 16-64 个字符。 将来无法检索此密码。
示例
以下示例演示如何调用此 API。
请求
下面展示了示例请求。 请求中 指定的 id 是应用程序的 id 属性的值,而不是 appId 属性的值。
POST https://graph.microsoft.com/v1.0/applications/{id}/addPassword
Content-type: application/json
{
"passwordCredential": {
"displayName": "Password friendly name"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var passwordCredential = new PasswordCredential
{
DisplayName = "Password friendly name"
};
await graphClient.Applications["{application-id}"]
.AddPassword(passwordCredential)
.Request()
.PostAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const passwordCredential = {
passwordCredential: {
displayName: 'Password friendly name'
}
};
await client.api('/applications/{id}/addPassword')
.post(passwordCredential);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/applications/{id}/addPassword"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphPasswordCredential *passwordCredential = [[MSGraphPasswordCredential alloc] init];
[passwordCredential setDisplayName:@"Password friendly name"];
payloadDictionary[@"passwordCredential"] = passwordCredential;
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];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
PasswordCredential passwordCredential = new PasswordCredential();
passwordCredential.displayName = "Password friendly name";
graphClient.applications("{id}")
.addPassword(ApplicationAddPasswordParameterSet
.newBuilder()
.withPasswordCredential(passwordCredential)
.build())
.buildRequest()
.post();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewPasswordCredentialRequestBody()
passwordCredential := msgraphsdk.NewPasswordCredential()
requestBody.SetPasswordCredential(passwordCredential)
displayName := "Password friendly name"
passwordCredential.SetDisplayName(&displayName)
applicationId := "application-id"
result, err := graphClient.ApplicationsById(&applicationId).AddPassword(application-id).Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Applications
$params = @{
PasswordCredential = @{
DisplayName = "Password friendly name"
}
}
Add-MgApplicationPassword -ApplicationId $applicationId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
响应
下面展示了示例响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"customKeyIdentifier": null,
"endDateTime": "2021-09-09T19:50:29.3086381Z",
"keyId": "f0b0b335-1d71-4883-8f98-567911bfdca6",
"startDateTime": "2019-09-09T19:50:29.3086381Z",
"secretText": "[6gyXA5S20@MN+WRXAJ]I-TO7g1:h2P8",
"hint": "[6g",
"displayName": "Password friendly name"
}