创建 identityProvider
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建一个标识提供程序资源,该资源的类型为请求正文中指定的类型。
在从 identityProviderBase 派生的提供程序类型中,当前可以在 Azure AD。 在 Azure AD B2C 中,此操作当前可以创建 socialIdentityProvider、openIdConnectIdentityProvider 或appleManagedIdentityProvider资源。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
IdentityProvider.ReadWrite.All |
| 委派(Microsoft 个人帐户) |
不支持。 |
| 应用程序 |
IdentityProvider.ReadWrite.All |
工作或学校帐户需要属于以下角色之一:
HTTP 请求
POST /identity/identityProviders
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,在请求正文中提供socialIdentityProvider对象的 JSON Azure AD。
在Azure AD B2C 提供 socialIdentityProvider、openIdConnectIdentityProvider 或appleManagedIdentityProvider对象的 JSON 表示形式。
下表中列出的所有属性都是必需的。
socialIdentityProvider 对象
| 属性 |
类型 |
说明 |
| clientId |
字符串 |
向标识提供程序注册应用程序时,获取应用程序的客户端标识符。 |
| clientSecret |
字符串 |
向标识提供程序注册时获取的应用程序的客户端密码。 这是只读的。 读取操作返回 ****。 |
| displayName |
字符串 |
标识提供程序的显示名称。 |
| identityProviderType |
String |
对于 B2B 方案,可能的值为: Google、 Facebook。 对于 B2C 方案,可能的值: Microsoft、 Google、 Amazon、 LinkedIn、 Facebook、 GitHub、 Twitter、 Weibo、 QQ、 WeChat。 |
openIdConnectIdentityProvider 对象
| 属性 |
类型 |
说明 |
| clientId |
字符串 |
使用身份提供程序注册应用时获取的应用客户端 ID。 |
| clientSecret |
字符串 |
使用身份提供程序注册应用时获取的应用客户端密码。 clientSecret 依赖于 responseType。 - 当 responseType
code 为 时,身份验证代码交换需要密码。 - 当 responseType 为密码时,由于没有代码交换,id_token直接从授权响应
id_token 返回密码。
|
| displayName |
字符串 |
标识提供程序的显示名称。 |
| domainHint |
String |
域提示可用于直接跳到指定标识提供程序的登录页面,而不是让用户在可用标识提供程序列表中进行选择。 |
| claimsMapping |
claimsMapping |
在 OIDC 提供程序将 ID 令牌发送回 Azure AD 后,Azure AD 需要能够将收到的令牌中的声明映射到 Azure AD 识别并使用的声明。 此复杂类型捕获该映射。 |
| metadataUrl |
String |
OpenID 元数据文档的 URL 连接提供程序。 每个 OpenID 连接标识提供程序都描述一个元数据文档,其中包含执行登录所需的大部分信息。 这包括要使用的 URL 以及服务的公共签名密钥的位置等信息。 OpenID 连接元数据文档始终位于 以 结尾的终结点 .well-known/openid-configuration 。 提供您添加的 OpenID 连接标识提供程序的元数据 URL。 |
| responseMode |
String |
响应模式定义用于将数据从自定义标识提供程序发送回 B2C Azure AD的方法。 可能的值 form_post query :、。 |
| responseType |
String |
响应类型描述在首次调用自定义标识提供程序的 authorization_endpoint时发送回的信息类型。 可能的值 code id_token token :、、。 |
| scope |
String |
范围定义要从自定义标识提供程序收集的信息和权限。 |
appleIdentityProvider 对象
| 属性 |
类型 |
说明 |
| displayName |
字符串 |
标识提供程序的显示名称。 |
| developerId |
String |
Apple 开发人员标识符。 |
| 服务 Id |
String |
Apple 服务标识符。 |
| keyId |
String |
Apple 密钥标识符。 |
| certificateData |
String |
证书中长文本字符串的证书数据可能是 null。 |
响应
如果成功,此方法在 Azure AD 租户的响应正文中返回 201 Created socialIdentityProvider对象的响应代码和 JSON 表示形式。
对于 Azure AD B2C 租户,此方法在响应正文中返回 201 Created socialIdentityProvider、openIdConnectIdentityProvider 或appleManagedIdentityProvider对象的响应代码和 JSON 表示形式。
如果失败,将返回 4xx 错误并显示具体详细信息。
示例
示例 1:创建特定的社会标识 提供程序 (Azure AD Azure AD B2C)
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/identity/identityProviders
Content-type: application/json
{
"@odata.type": "microsoft.graph.socialIdentityProvider",
"displayName": "Login with Amazon",
"identityProviderType": "Amazon",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "000000000000"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var identityProviderBase = new SocialIdentityProvider
{
DisplayName = "Login with Amazon",
IdentityProviderType = "Amazon",
ClientId = "56433757-cadd-4135-8431-2c9e3fd68ae8",
ClientSecret = "000000000000"
};
await graphClient.Identity.IdentityProviders
.Request()
.AddAsync(identityProviderBase);
const options = {
authProvider,
};
const client = Client.init(options);
const identityProviderBase = {
'@odata.type': 'microsoft.graph.socialIdentityProvider',
displayName: 'Login with Amazon',
identityProviderType: 'Amazon',
clientId: '56433757-cadd-4135-8431-2c9e3fd68ae8',
clientSecret: '000000000000'
};
await client.api('/identity/identityProviders')
.version('beta')
.post(identityProviderBase);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identity/identityProviders"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphIdentityProviderBase *identityProviderBase = [[MSGraphIdentityProviderBase alloc] init];
[identityProviderBase setDisplayName:@"Login with Amazon"];
[identityProviderBase setIdentityProviderType:@"Amazon"];
[identityProviderBase setClientId:@"56433757-cadd-4135-8431-2c9e3fd68ae8"];
[identityProviderBase setClientSecret:@"000000000000"];
NSError *error;
NSData *identityProviderBaseData = [identityProviderBase getSerializedDataWithError:&error];
[urlRequest setHTTPBody:identityProviderBaseData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
SocialIdentityProvider identityProviderBase = new SocialIdentityProvider();
identityProviderBase.displayName = "Login with Amazon";
identityProviderBase.identityProviderType = "Amazon";
identityProviderBase.clientId = "56433757-cadd-4135-8431-2c9e3fd68ae8";
identityProviderBase.clientSecret = "000000000000";
graphClient.identity().identityProviders()
.buildRequest()
.post(identityProviderBase);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewIdentityProviderBase()
displayName := "Login with Amazon"
requestBody.SetDisplayName(&displayName)
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.type": "microsoft.graph.socialIdentityProvider",
"identityProviderType": "Amazon",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "000000000000",
}
result, err := graphClient.Identity().IdentityProviders().Post(requestBody)
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.type": "microsoft.graph.socialIdentityProvider",
"id": "Amazon-OAUTH",
"displayName": "Login with Amazon",
"identityProviderType": "Amazon",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "000000000000"
}
示例 2:仅为 B2C 连接创建 (OpenID Azure AD提供程序)
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/identity/identityProviders
Content-type: application/json
{
"@odata.type": "microsoft.graph.openIdConnectIdentityProvider",
"displayName": "Login with the Contoso identity provider",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "12345",
"claimsMapping": {
"userId": "myUserId",
"givenName": "myGivenName",
"surname": "mySurname",
"email": "myEmail",
"displayName": "myDisplayName"
},
"domainHint": "mycustomoidc",
"metadataUrl": "https://mycustomoidc.com/.well-known/openid-configuration",
"responseMode": "form_post",
"responseType": "code",
"scope": "openid"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var identityProviderBase = new OpenIdConnectIdentityProvider
{
DisplayName = "Login with the Contoso identity provider",
ClientId = "56433757-cadd-4135-8431-2c9e3fd68ae8",
ClientSecret = "12345",
ClaimsMapping = new ClaimsMapping
{
UserId = "myUserId",
GivenName = "myGivenName",
Surname = "mySurname",
Email = "myEmail",
DisplayName = "myDisplayName"
},
DomainHint = "mycustomoidc",
MetadataUrl = "https://mycustomoidc.com/.well-known/openid-configuration",
ResponseMode = OpenIdConnectResponseMode.Form_post,
ResponseType = OpenIdConnectResponseTypes.Code,
Scope = "openid"
};
await graphClient.Identity.IdentityProviders
.Request()
.AddAsync(identityProviderBase);
const options = {
authProvider,
};
const client = Client.init(options);
const identityProviderBase = {
'@odata.type': 'microsoft.graph.openIdConnectIdentityProvider',
displayName: 'Login with the Contoso identity provider',
clientId: '56433757-cadd-4135-8431-2c9e3fd68ae8',
clientSecret: '12345',
claimsMapping: {
userId: 'myUserId',
givenName: 'myGivenName',
surname: 'mySurname',
email: 'myEmail',
displayName: 'myDisplayName'
},
domainHint: 'mycustomoidc',
metadataUrl: 'https://mycustomoidc.com/.well-known/openid-configuration',
responseMode: 'form_post',
responseType: 'code',
scope: 'openid'
};
await client.api('/identity/identityProviders')
.version('beta')
.post(identityProviderBase);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identity/identityProviders"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphIdentityProviderBase *identityProviderBase = [[MSGraphIdentityProviderBase alloc] init];
[identityProviderBase setDisplayName:@"Login with the Contoso identity provider"];
[identityProviderBase setClientId:@"56433757-cadd-4135-8431-2c9e3fd68ae8"];
[identityProviderBase setClientSecret:@"12345"];
MSGraphClaimsMapping *claimsMapping = [[MSGraphClaimsMapping alloc] init];
[claimsMapping setUserId:@"myUserId"];
[claimsMapping setGivenName:@"myGivenName"];
[claimsMapping setSurname:@"mySurname"];
[claimsMapping setEmail:@"myEmail"];
[claimsMapping setDisplayName:@"myDisplayName"];
[identityProviderBase setClaimsMapping:claimsMapping];
[identityProviderBase setDomainHint:@"mycustomoidc"];
[identityProviderBase setMetadataUrl:@"https://mycustomoidc.com/.well-known/openid-configuration"];
[identityProviderBase setResponseMode: [MSGraphOpenIdConnectResponseMode form_post]];
[identityProviderBase setResponseType: [MSGraphOpenIdConnectResponseTypes code]];
[identityProviderBase setScope:@"openid"];
NSError *error;
NSData *identityProviderBaseData = [identityProviderBase getSerializedDataWithError:&error];
[urlRequest setHTTPBody:identityProviderBaseData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
OpenIdConnectIdentityProvider identityProviderBase = new OpenIdConnectIdentityProvider();
identityProviderBase.displayName = "Login with the Contoso identity provider";
identityProviderBase.clientId = "56433757-cadd-4135-8431-2c9e3fd68ae8";
identityProviderBase.clientSecret = "12345";
ClaimsMapping claimsMapping = new ClaimsMapping();
claimsMapping.userId = "myUserId";
claimsMapping.givenName = "myGivenName";
claimsMapping.surname = "mySurname";
claimsMapping.email = "myEmail";
claimsMapping.displayName = "myDisplayName";
identityProviderBase.claimsMapping = claimsMapping;
identityProviderBase.domainHint = "mycustomoidc";
identityProviderBase.metadataUrl = "https://mycustomoidc.com/.well-known/openid-configuration";
identityProviderBase.responseMode = OpenIdConnectResponseMode.FORM_POST;
identityProviderBase.responseType = EnumSet.of(OpenIdConnectResponseTypes.CODE);
identityProviderBase.scope = "openid";
graphClient.identity().identityProviders()
.buildRequest()
.post(identityProviderBase);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewIdentityProviderBase()
displayName := "Login with the Contoso identity provider"
requestBody.SetDisplayName(&displayName)
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.type": "microsoft.graph.openIdConnectIdentityProvider",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "12345",
"domainHint": "mycustomoidc",
"metadataUrl": "https://mycustomoidc.com/.well-known/openid-configuration",
"responseMode": "form_post",
"responseType": "code",
"scope": "openid",
}
result, err := graphClient.Identity().IdentityProviders().Post(requestBody)
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.type": "microsoft.graph.openIdConnectIdentityProvider",
"id": "OIDC-V1-MyTest-085a8a0c-58cb-4b6d-8e07-1328ea404e1a",
"displayName": "Login with the Contoso identity provider",
"clientId": "56433757-cadd-4135-8431-2c9e3fd68ae8",
"clientSecret": "12345",
"claimsMapping": {
"userId": "myUserId",
"givenName": "myGivenName",
"surname": "mySurname",
"email": "myEmail",
"displayName": "myDisplayName"
},
"domainHint": "mycustomoidc",
"metadataUrl": "https://mycustomoidc.com/.well-known/openid-configuration",
"responseMode": "form_post",
"responseType": "code",
"scope": "openid"
}
示例 3:仅为 (B2C Azure AD检索 Apple 标识)
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/identity/identityProviders
Content-type: application/json
{
"@odata.type": "microsoft.graph.appleManagedIdentityProvider",
"displayName": "Sign in with Apple",
"developerId": "UBF8T346G9",
"serviceId": "com.microsoft.rts.b2c.test.client",
"keyId": "99P6D879C4",
"certificateData": "******"
}
const options = {
authProvider,
};
const client = Client.init(options);
const identityProviderBase = {
'@odata.type': 'microsoft.graph.appleManagedIdentityProvider',
displayName: 'Sign in with Apple',
developerId: 'UBF8T346G9',
serviceId: 'com.microsoft.rts.b2c.test.client',
keyId: '99P6D879C4',
certificateData: '******'
};
await client.api('/identity/identityProviders')
.version('beta')
.post(identityProviderBase);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identity/identityProviders"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphIdentityProviderBase *identityProviderBase = [[MSGraphIdentityProviderBase alloc] init];
[identityProviderBase setDisplayName:@"Sign in with Apple"];
[identityProviderBase setDeveloperId:@"UBF8T346G9"];
[identityProviderBase setServiceId:@"com.microsoft.rts.b2c.test.client"];
[identityProviderBase setKeyId:@"99P6D879C4"];
[identityProviderBase setCertificateData:@"******"];
NSError *error;
NSData *identityProviderBaseData = [identityProviderBase getSerializedDataWithError:&error];
[urlRequest setHTTPBody:identityProviderBaseData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var identityProviderBase = new AppleManagedIdentityProvider
{
DisplayName = "Sign in with Apple",
DeveloperId = "UBF8T346G9",
ServiceId = "com.microsoft.rts.b2c.test.client",
KeyId = "99P6D879C4",
CertificateData = "******"
};
await graphClient.Identity.IdentityProviders
.Request()
.AddAsync(identityProviderBase);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
AppleManagedIdentityProvider identityProviderBase = new AppleManagedIdentityProvider();
identityProviderBase.displayName = "Sign in with Apple";
identityProviderBase.developerId = "UBF8T346G9";
identityProviderBase.serviceId = "com.microsoft.rts.b2c.test.client";
identityProviderBase.keyId = "99P6D879C4";
identityProviderBase.certificateData = "******";
graphClient.identity().identityProviders()
.buildRequest()
.post(identityProviderBase);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewIdentityProviderBase()
displayName := "Sign in with Apple"
requestBody.SetDisplayName(&displayName)
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.type": "microsoft.graph.appleManagedIdentityProvider",
"developerId": "UBF8T346G9",
"serviceId": "com.microsoft.rts.b2c.test.client",
"keyId": "99P6D879C4",
"certificateData": "******",
}
result, err := graphClient.Identity().IdentityProviders().Post(requestBody)
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.type": "microsoft.graph.appleManagedIdentityProvider",
"id": "Apple-Managed-OIDC",
"displayName": "Sign in with Apple",
"developerId": "UBF8T346G9",
"serviceId": "com.microsoft.rts.b2c.test.client",
"keyId": "99P6D879C4",
"certificateData": "******"
}