identityApiConnector: uploadClientCertificate
Article
02/16/2022
2 minutes to read
4 contributors
In this article
Namespace: microsoft.graph
Upload a PKCS 12 format key (.pfx) to an API connector's authentication configuration. The input is a base-64 encoded value of the PKCS 12 certificate contents. This method returns an apiConnector .
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
APIConnectors.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
APIConnectors.ReadWrite.All
The work or school account needs to belong to one of the following roles:
Global administrator
External Identity User Flow administrator
HTTP request
POST /identity/apiconnectors/{id}/uploadClientCertificate
Name
Description
Authorization
Bearer {token}. Required.
Content-type
application/json. Required.
Request body
In the request body, provide a JSON object with the following parameters.
Property
Type
Description
pkcs12Value
String
This is the field for sending the pfx content. The value should be a base-64 encoded version of the actual certificate content. Required.
password
String
This is the password for the pfx file. Required. If no password is used, must still provide a value of ""
.
Response
If successful, this method returns a 200 OK
response code and the apiConnector whose authenticationConfiguration
contains the public information of the client certificate.
Examples
Request
The following is an example of the request.
POST https://graph.microsoft.com/v1.0/identity/apiconnectors/{id}/uploadClientCertificate
Content-type: application/json
{
"pkcs12Value": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
"password": "<password>"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA";
var password = "<password>";
await graphClient.Identity.ApiConnectors["{identityApiConnector-id}"]
.UploadClientCertificate(pkcs12Value,password)
.Request()
.PostAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const identityApiConnector = {
pkcs12Value: 'eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA',
password: '<password>'
};
await client.api('/identity/apiconnectors/{id}/uploadClientCertificate')
.post(identityApiConnector);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identity/apiconnectors/{id}/uploadClientCertificate"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSString *pkcs12Value = @"eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA";
payloadDictionary[@"pkcs12Value"] = pkcs12Value;
NSString *password = @"<password>";
payloadDictionary[@"password"] = password;
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];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
String pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA";
String password = "<password>";
graphClient.identity().apiConnectors("{id}")
.uploadClientCertificate(IdentityApiConnectorUploadClientCertificateParameterSet
.newBuilder()
.withPkcs12Value(pkcs12Value)
.withPassword(password)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
pkcs12Value := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA"
requestBody.SetPkcs12Value(&pkcs12Value)
password := "<password>"
requestBody.SetPassword(&password)
identityApiConnectorId := "identityApiConnector-id"
result, err := graphClient.Identity().ApiConnectorsById(&identityApiConnectorId).UploadClientCertificate(identityApiConnector-id).Post(requestBody)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
Note: authenticationConfiguration
in the response is of type microsoft.graph.clientCertificateAuthentication because this represents the public information of uploaded certificates.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/apiConnectors/$entity",
"id": "45715bb8-13f9-4bf6-927f-ef96c102d394",
"displayName": "My API connector",
"targetUrl": "https://api.contoso.com/endpoint",
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.clientCertificateAuthentication",
"certificateList": [
{
"thumbprint": "0EB255CC895477798BA418B378255204304897AD",
"notAfter": 1666350522,
"notBefore": 1508670522,
"isActive": true
}
]
}
}