创建 identityApiConnector
命名空间:microsoft.graph
创建新的 identityApiConnector 对象。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
APIConnectors.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
APIConnectors.ReadWrite.All |
工作或学校帐户需要属于以下角色之一:
HTTP 请求
POST /identity/apiConnectors
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供 identityApiConnector 对象的 JSON 表示形式。
下表显示创建 identityApiConnector 时所需的属性。
响应
如果成功,此方法在响应 201 Created 正文中返回 响应代码和 identityApiConnector 对象。
示例
示例 1:使用基本身份验证创建 API 连接器
请求
下面展示了示例请求。
POST https://graph.microsoft.com/v1.0/identity/apiConnectors
Content-Type: application/json
{
"displayName":"Test API",
"targetUrl":"https://someapi.com/api",
"authenticationConfiguration": {
"@odata.type":"#microsoft.graph.basicAuthentication",
"username": "MyUsername",
"password": "MyPassword"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var identityApiConnector = new IdentityApiConnector
{
DisplayName = "Test API",
TargetUrl = "https://someotherapi.com/api",
AuthenticationConfiguration = new Pkcs12Certificate
{
Pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
Password = "CertificatePassword"
}
};
await graphClient.Identity.ApiConnectors
.Request()
.AddAsync(identityApiConnector);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const identityApiConnector = {
displayName: 'Test API',
targetUrl: 'https://someotherapi.com/api',
authenticationConfiguration: {
'@odata.type':'#microsoft.graph.pkcs12Certificate',
pkcs12Value: 'eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA',
password: 'CertificatePassword'
}
};
await client.api('/identity/apiConnectors')
.post(identityApiConnector);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identity/apiConnectors"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphIdentityApiConnector *identityApiConnector = [[MSGraphIdentityApiConnector alloc] init];
[identityApiConnector setDisplayName:@"Test API"];
[identityApiConnector setTargetUrl:@"https://someotherapi.com/api"];
MSGraphApiAuthenticationConfigurationBase *authenticationConfiguration = [[MSGraphApiAuthenticationConfigurationBase alloc] init];
[authenticationConfiguration setPkcs12Value:@"eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA"];
[authenticationConfiguration setPassword:@"CertificatePassword"];
[identityApiConnector setAuthenticationConfiguration:authenticationConfiguration];
NSError *error;
NSData *identityApiConnectorData = [identityApiConnector getSerializedDataWithError:&error];
[urlRequest setHTTPBody:identityApiConnectorData];
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();
IdentityApiConnector identityApiConnector = new IdentityApiConnector();
identityApiConnector.displayName = "Test API";
identityApiConnector.targetUrl = "https://someotherapi.com/api";
Pkcs12Certificate authenticationConfiguration = new Pkcs12Certificate();
authenticationConfiguration.pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA";
authenticationConfiguration.password = "CertificatePassword";
identityApiConnector.authenticationConfiguration = authenticationConfiguration;
graphClient.identity().apiConnectors()
.buildRequest()
.post(identityApiConnector);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewIdentityApiConnector()
displayName := "Test API"
requestBody.SetDisplayName(&displayName)
targetUrl := "https://someotherapi.com/api"
requestBody.SetTargetUrl(&targetUrl)
authenticationConfiguration := msgraphsdk.NewApiAuthenticationConfigurationBase()
requestBody.SetAuthenticationConfiguration(authenticationConfiguration)
authenticationConfiguration.SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.pkcs12Certificate",
"pkcs12Value": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
"password": "CertificatePassword",
}
result, err := graphClient.Identity().ApiConnectors().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/apiConnectors/$entity",
"id":"45715bb8-13f9-4bf6-927f-ef96c102d394",
"displayName": "Test API",
"targetUrl": "https://someapi.com/api",
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.basicAuthentication",
"username": "MyUsername",
"password": "******"
}
}
示例 2:使用客户端证书身份验证创建 API 连接器
请求
下面展示了示例请求。
注意: authenticationConfiguration 请求中的 类型为 microsoft.graph.pkcs12certificate,表示上载或创建时所需的证书配置。
POST https://graph.microsoft.com/v1.0/identity/apiConnectors
Content-Type: application/json
{
"displayName":"Test API",
"targetUrl":"https://someotherapi.com/api",
"authenticationConfiguration": {
"@odata.type":"#microsoft.graph.pkcs12Certificate",
"pkcs12Value": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
"password": "CertificatePassword"
}
}
响应
下面展示了示例响应。
注意: authenticationConfiguration 响应中的 类型为 microsoft.graph.clientCertificateAuthentication ,因为这表示已上载证书的公共信息。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/apiConnectors/$entity",
"id":"45715bb8-13f9-4bf6-927f-ef96c102d394",
"displayName": "Test API",
"targetUrl": "https://someotherapi.com/api",
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.clientCertificateAuthentication",
"certificateList": [
{
"thumbprint": "0EB255CC895477798BA418B378255204304897AD",
"notAfter": 1666350522,
"notBefore": 1508670522,
"isActive": true
}
]
}
}