创建 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 方案,可能的值为: GoogleFacebook。 对于 B2C 方案,可能的值: MicrosoftGoogleAmazonLinkedInFacebookGitHubTwitterWeiboQQWeChat

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"
}

响应

下面展示了示例响应。

注意: 为了提高可读性,可能缩短了此处显示的响应对象。

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"
}

响应

下面展示了示例响应。

注意: 为了提高可读性,可能缩短了此处显示的响应对象。

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": "******"
}

响应

下面展示了示例响应。

注意: 为了提高可读性,可能缩短了此处显示的响应对象。

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": "******"
}