servicePrincipal:addTokenSigningCertificate
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建自签名签名证书并返回 selfSignedCertificate 对象,该对象是生成的证书的公共部分。 自签名签名证书由添加到 servicePrincipal 中的以下对象组成:
所有对象具有相同的 customKeyIdentifier 值。
passwordCredential 用于打开 PFX 文件 (私钥) 。 它和关联的私钥对象具有相同的 keyId 值。 创建期间通过 displayName 属性设置后,证书的主题将无法更新。 startDateTime 设置为使用 操作创建证书的同一时间。 endDateTime 可在证书创建后最多三年。
权限
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Application.ReadWrite.All、Directory.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
无。 |
| 应用程序 |
Application.ReadWrite.OwnedBy、Application.ReadWrite.All、Directory.ReadWrite.All |
HTTP 请求
POST /servicePrincipals/{id}/addTokenSigningCertificate
请求正文
在请求正文中,提供以下必需属性。
| 属性 |
类型 |
说明 |
| displayName |
string |
密钥的友好名称。 它必须以 开始 CN=。 |
| endDateTime |
DateTimeOffset |
凭据过期的日期和时间。 从证书创建之日起,最多 3 年。 如果未提供,则默认值为自创建时起三年。 时间戳类型表示使用 ISO 8601 格式的日期和时间信息,并且始终采用 UTC 时间。 例如,2014 年 1 月 1 日午夜 UTC 为 2014-01-01T00:00:00Z。 |
响应
如果成功,此方法在响应 200 OK 正文中返回 响应代码和新 selfSignedCertificate 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/servicePrincipals/004375c5-6e2e-4dec-95e3-626838cb9f80/addTokenSigningCertificate
Content-type: application/json
{
"displayName":"CN=customDisplayName",
"endDateTime":"2024-01-25T00:00:00Z"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var displayName = "CN=customDisplayName";
var endDateTime = DateTimeOffset.Parse("2024-01-25T00:00:00Z");
await graphClient.ServicePrincipals["{servicePrincipal-id}"]
.AddTokenSigningCertificate(displayName,endDateTime)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
const selfSignedCertificate = {
displayName: 'CN=customDisplayName',
endDateTime: '2024-01-25T00:00:00Z'
};
await client.api('/servicePrincipals/004375c5-6e2e-4dec-95e3-626838cb9f80/addTokenSigningCertificate')
.version('beta')
.post(selfSignedCertificate);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/servicePrincipals/004375c5-6e2e-4dec-95e3-626838cb9f80/addTokenSigningCertificate"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSString *displayName = @"CN=customDisplayName";
payloadDictionary[@"displayName"] = displayName;
NSString *endDateTimeDateTimeString = @"01/25/2024 00:00:00";
NSDate *endDateTime = [NSDate ms_dateFromString: endDateTimeDateTimeString];
payloadDictionary[@"endDateTime"] = endDateTime;
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 displayName = "CN=customDisplayName";
OffsetDateTime endDateTime = OffsetDateTimeSerializer.deserialize("01/25/2024 00:00:00");
graphClient.servicePrincipals("004375c5-6e2e-4dec-95e3-626838cb9f80")
.addTokenSigningCertificate(ServicePrincipalAddTokenSigningCertificateParameterSet
.newBuilder()
.withDisplayName(displayName)
.withEndDateTime(endDateTime)
.build())
.buildRequest()
.post();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
displayName := "CN=customDisplayName"
requestBody.SetDisplayName(&displayName)
endDateTime, err := time.Parse(time.RFC3339, "2024-01-25T00:00:00Z")
requestBody.SetEndDateTime(&endDateTime)
servicePrincipalId := "servicePrincipal-id"
result, err := graphClient.ServicePrincipalsById(&servicePrincipalId).AddTokenSigningCertificate(servicePrincipal-id).Post(requestBody)
Import-Module Microsoft.Graph.Applications
$params = @{
DisplayName = "CN=customDisplayName"
EndDateTime = [System.DateTime]::Parse("2024-01-25T00:00:00Z")
}
Add-MgServicePrincipalTokenSigningCertificate -ServicePrincipalId $servicePrincipalId -BodyParameter $params
响应
下面展示了示例响应。
HTTP/1.1 200 OK
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.selfSignedCertificate",
"customKeyIdentifier": "2iD8ppbE+D6Kmu1ZvjM2jtQh88E=",
"displayName": "CN=customDisplayName",
"endDateTime": "2024-01-25T00:00:00Z",
"key": "MIICuDCCAaCgAwIBAgIIYXJsNtL4oUMwDQYJKoZIhvcNAQEL...StP8s/w==",
"keyId": "93bc223f-7235-4b9c-beea-d66847531c49",
"startDateTime": "2021-05-05T18:38:51.8100763Z",
"thumbprint": "DA20FCA696C4F83E8A9AED59BE33368ED421F3C1",
"type": "AsymmetricX509Cert",
"usage": "Verify"
}