Terraform – Azure 如何创建 B2C 身份提供者

huangapple go评论130阅读模式
英文:

Terraform - Azure How to create B2C identity provider

问题

我有以下的 `terraform` 代码来创建一个 `azure` - `azurerm_aadb2c_directory` 如下所示:

```hcl
resource "azurerm_aadb2c_directory" "example" {
  country_code            = var.b2c_country_code
  data_residency_location = var.b2c_data_residency_location
  display_name            = var.b2c_display_name
  domain_name             = "${var.b2c_display_name}.onmicrosoft.com"
  resource_group_name     = var.b2c_rg_name
  sku_name                = var.b2c_sku
}

现在,我想创建一个身份提供者(如下截图所示),但我找不到相应的 terraform 资源。

有人能帮我找到正确的 terraform 资源,以及如何修改/创建/定制如下截图中所示的页面吗?

Terraform – Azure 如何创建 B2C 身份提供者


<details>
<summary>英文:</summary>

I have the following `terraform` code to create an `azure` - `azurerm_aadb2c_directory` as below:

resource "azurerm_aadb2c_directory" "example" {
country_code = var.b2c_country_code
data_residency_location = var.b2c_data_residency_location
display_name = var.b2c_display_name
domain_name = "${var.b2c_display_name}.onmicrosoft.com"
resource_group_name = var.b2c_rg_name
sku_name = var.b2c_sku
}


And Now I want to create one of the Identity Providers (as mentioned in the below screenshot) But I can&#39;t find the `terraform` resource for that.

Can someone help me find the right `terraform` resource and how to modify/create/customize the page as show in the below screen snip?

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/A3K7j.jpg

</details>


# 答案1
**得分**: 1

I'm here to provide translations for the content you've shared. Here's the translation of the provided content:

默认情况下,Azure Terraform资源提供程序不包含配置以设置Azure AD B2C的身份提供程序。

```hcl
resource &quot;azurerm_aadb2c_directory&quot; &quot;example&quot; {
  country_code            = &quot;US&quot;
  data_residency_location = &quot;United States&quot;
  display_name            = &quot;example-b2c-tenant&quot;
  domain_name             = &quot;exampleb2ctenant.onmicrosoft.com&quot;
  resource_group_name     = &quot;example-rg&quot;
  sku_name                = &quot;PremiumP1&quot;
}

输出:-

Terraform – Azure 如何创建 B2C 身份提供者

Terraform – Azure 如何创建 B2C 身份提供者

另一个提供程序用于获取现有Azure AD B2C租户的属性。

data &quot;azurerm_aadb2c_directory&quot; &quot;example&quot; {
  resource_group_name = &quot;example-rg&quot;
  domain_name         = &quot;exampleb2ctenant.onmicrosoft.com&quot;
}

output &quot;tenant_id&quot; {
  value = data.azurerm_aadb2c_directory.example.tenant_id
}

输出:-

Terraform – Azure 如何创建 B2C 身份提供者

我还尝试通过Microsoft Rest API来更新AAD B2C中的IDP,但没有API调用可以在Azure AD B2C中创建或更新IDP。

但是,您可以使用以下代码调用Rest API来更新Azure AD B2C中应用程序的社交IDP或本地IDP的密码凭据:-

创建了一个Google开发者IDP并从已注册的应用程序获取客户端ID和客户端密钥:-

Terraform – Azure 如何创建 B2C 身份提供者

terraform {

required_providers {

azurerm  =  {

source = &quot;hashicorp/azurerm&quot;

version = &quot;3.47.0&quot;

}

}

}

  

provider  &quot;azurerm&quot; {

features {}

subscription_id  =  &quot;<subscription-id>&quot;

}

  

resource  &quot;azurerm_resource_group&quot;  &quot;appgrp&quot; {

name  =  &quot;app-grp&quot;

location  =  &quot;West Europe&quot;

}

  

resource  &quot;null_resource&quot;  &quot;configure_social_idp&quot; {

provisioner  &quot;local-exec&quot; {

command  =  &lt;&lt;EOF

set AZURE_TENANT_ID=&quot;<tenant-id>&quot;

set AZURE_CLIENT_ID=&quot;<client-id>&quot;

set AZURE_CLIENT_SECRET=&quot;<client-secret>&quot;

set AZURE_AD_B2C_APP_ID=&quot;<app-id>&quot;

  

curl -X POST \

-H &quot;Authorization: Bearer $(az account get-access-token --resource https://graph.windows.net | jq -r .accessToken)&quot; \

-H &quot;Content-Type: application/json&quot; \

-d '{

&quot;keyCredential&quot;: {

&quot;customKeyIdentifier&quot;: null,

&quot;displayName&quot;: &quot;Google&quot;,

&quot;endDateTime&quot;: null,

&quot;key&quot;: null,

&quot;startDateTime&quot;: null,

&quot;type&quot;: &quot;Symmetric&quot;,

&quot;usage&quot;: &quot;Verify&quot;,

&quot;value&quot;: &quot;<idp-password>&quot;

},

&quot;passwordCredential&quot;: null,

&quot;publicClient&quot;: null,

&quot;replyUrls&quot;: [],

&quot;requiredResourceAccess&quot;: [],

&quot;web&quot;: null

}' \

"https://graph.windows.net/<tenant-id>/applications/<object-id>/addKeyCredential?api-version=1.6"

EOF

}

}

输出:-

Terraform – Azure 如何创建 B2C 身份提供者

Terraform – Azure 如何创建 B2C 身份提供者

参考资料:-

Terraform Registry

azurerm_aadb2c_directory | Data Sources | hashicorp/azurerm | Terraform Registry

B2C Tenants - Create - REST API (Azure Azure AD B2C) | Microsoft Learn

B2C Tenants - Update - REST API (Azure Azure AD B2C) | Microsoft Learn

英文:

By default Azure Terraform Resource provider does not contain configurations to set the Identity Provider for Azure AD B2C.

resource &quot;azurerm_aadb2c_directory&quot; &quot;example&quot; {
  country_code            = &quot;US&quot;
  data_residency_location = &quot;United States&quot;
  display_name            = &quot;example-b2c-tenant&quot;
  domain_name             = &quot;exampleb2ctenant.onmicrosoft.com&quot;
  resource_group_name     = &quot;example-rg&quot;
  sku_name                = &quot;PremiumP1&quot;
}

Output:-

Terraform – Azure 如何创建 B2C 身份提供者

Terraform – Azure 如何创建 B2C 身份提供者

And other provider is for getting the properties of the existing Azure AD B2C tenant.

data &quot;azurerm_aadb2c_directory&quot; &quot;example&quot; {
  resource_group_name = &quot;example-rg&quot;
  domain_name         = &quot;exampleb2ctenant.onmicrosoft.com&quot;
}

output &quot;tenant_id&quot; {
  value = data.azurerm_aadb2c_directory.example.tenant_id
}

Output:-

Terraform – Azure 如何创建 B2C 身份提供者

> I also tried checking Microsoft Rest API to update IDP in AAD B2C via
> terraform, But there’s no API call to create or update IDP in azure AD
> B2C.

But You can call a Rest API to update the password credentials of an App in your Azure AD B2C with social IDP or local IDP by using the code below:-

Created one google developer IDP and got the client ID and Client secret from the registered app:-

Terraform – Azure 如何创建 B2C 身份提供者

terraform {

required_providers {

azurerm  =  {

source = &quot;hashicorp/azurerm&quot;

version = &quot;3.47.0&quot;

}

}

}

  
  

provider  &quot;azurerm&quot; {

features {}

subscription_id  =  &quot;&lt;subscription-id&gt;&quot;

}

  

resource  &quot;azurerm_resource_group&quot;  &quot;appgrp&quot; {

name  =  &quot;app-grp&quot;

location  =  &quot;West Europe&quot;

}

  

resource  &quot;null_resource&quot;  &quot;configure_social_idp&quot; {

provisioner  &quot;local-exec&quot; {

command  =  &lt;&lt;EOF

set AZURE_TENANT_ID=&quot;&lt;tenant-id&gt;&quot;

set AZURE_CLIENT_ID=&quot;&lt;client-id&gt;&quot;

set AZURE_CLIENT_SECRET=&quot;&lt;client-secret&gt;&quot;

set AZURE_AD_B2C_APP_ID=&quot;&lt;app-id&gt;&quot;

  
  

curl -X POST \

-H &quot;Authorization: Bearer $(az account get-access-token --resource https://graph.windows.net | jq -r .accessToken)&quot; \

-H &quot;Content-Type: application/json&quot; \

-d &#39;{

&quot;keyCredential&quot;: {

&quot;customKeyIdentifier&quot;: null,

&quot;displayName&quot;: &quot;Google&quot;,

&quot;endDateTime&quot;: null,

&quot;key&quot;: null,

&quot;startDateTime&quot;: null,

&quot;type&quot;: &quot;Symmetric&quot;,

&quot;usage&quot;: &quot;Verify&quot;,

&quot;value&quot;: &quot;&lt;idp-password&gt;&quot;

},

&quot;passwordCredential&quot;: null,

&quot;publicClient&quot;: null,

&quot;replyUrls&quot;: [],

&quot;requiredResourceAccess&quot;: [],

&quot;web&quot;: null

}&#39; \

&quot;https://graph.windows.net/\&lt;tenant-id&gt;/applications/\&lt;object-id&gt;/addKeyCredential?api-version=1.6&quot;

EOF

}

}

Output:-

Terraform – Azure 如何创建 B2C 身份提供者

Terraform – Azure 如何创建 B2C 身份提供者

References:-

Terraform Registry

azurerm_aadb2c_directory | Data Sources | hashicorp/azurerm | Terraform Registry

B2C Tenants - Create - REST API (Azure Azure AD B2C) | Microsoft Learn

B2C Tenants - Update - REST API (Azure Azure AD B2C) | Microsoft Learn

huangapple
  • 本文由 发表于 2023年3月9日 21:41:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定