terraform-provider-azuread icon indicating copy to clipboard operation
terraform-provider-azuread copied to clipboard

Azure AD B2C Support

Open markti opened this issue 5 years ago • 23 comments

Does this provider support Azure AD B2C? If not, what provider can I use to support Azure AD B2C?

markti avatar Nov 08 '19 22:11 markti

i am also interested in this

mikebollandajw avatar Nov 26 '19 17:11 mikebollandajw

I'd love this as well!

jackbatzner avatar Dec 16 '19 20:12 jackbatzner

For application, we can use this provider to create an application in the B2C directory.

The key point it that you must manually create a service principle and use this service principle to create an application the B2C directory by Terraform.

The example is below.

provider "azuread" {
  version = "=0.3.0"
  subscription_id = "There is no subscription in the B2C directory, so you can use the tenant id as subscription id."
  client_id = "The id of service principle"
  client_secret = "The secrect created in the service principle"
  tenant_id = "tenant id"
}

resource "azuread_application" "example" {
  name                       = "example"
  homepage                   = "https://example"
  reply_urls                 = ["https://example"]
  available_to_other_tenants = false
  oauth2_allow_implicit_flow = true
}

hhao01-becls avatar Feb 06 '20 02:02 hhao01-becls

Do we have any plan to support Azure Active Directory B2C? We can use azuread provider to create an application in the B2C directory. We also need the following supports:

  • Trust Framework policy (custom policy)
  • User Flow

For now, the beta version in Microsoft Graph is in preview, which supports managing the Trust Framework policy and user flow. The details refer to trustFrameworkPolicy resource type and UserFlow resource type

hhao01-becls avatar Feb 06 '20 03:02 hhao01-becls

Would love this too!

AshleyPoole avatar Apr 29 '20 07:04 AshleyPoole

Unfortunately at the moment the Azure SDK for Go doesn't support MS Graph, so we can't yet manage B2C policies or user flows.

You should however, as mentioned by @hhao01-becls, now be able to manage B2C Applications using the azuread_application resource since these were recently made cross-compatible with regular app registrations.

manicminer avatar May 19 '20 04:05 manicminer

When creating a new application in B2C there is the option under Supported Account Types for "Accounts in any organizational directory or any identity provider. For authenticating users with Azure AD B2C."

Screen Shot 2020-05-26 at 2 05 00 PM

I know that azuread_application has the param available_to_other_tenants https://www.terraform.io/docs/providers/azuread/r/application.html#available_to_other_tenants however I don't think there is a param that can configure an application with that Supported Account Type.

I am playing around with this and will update here if I find anything further.

Edit: It appears this is a limitation of the current Go SDK which is not using the Microsoft Graph API. With Graph you can configure an application like:

"signInAudience": "AzureADandPersonalMicrosoftAccount",

https://docs.microsoft.com/en-us/graph/api/resources/application?view=graph-rest-beta

erikanderson avatar May 26 '20 20:05 erikanderson

This would be great!

bytemech avatar Mar 03 '21 08:03 bytemech

Btw. azurerm provider supports some B2C resources, e.g. api_management_identity_provider_aadb2c.

kenorb avatar Jun 09 '21 10:06 kenorb

Would this scenario be enabled by the 2.0 milestone? Currently I get

│ Error: expected sign_in_audience to be one of [AzureADMyOrg AzureADMultipleOrgs], got AzureADandPersonalMicrosoftAccount
│
│   with [...],
│   on [..] line 9, in resource "azuread_application" "web":
│    9:   sign_in_audience = "AzureADandPersonalMicrosoftAccount"
│

dvdvorle avatar Jul 06 '21 11:07 dvdvorle

Support for all values for sign_in_audience was already merged in preparation for 2.0, see #461. Thanks!

manicminer avatar Jul 06 '21 12:07 manicminer

@manicminer I know 2.0 isn't released yet, but can I use a dev version now with a different source in required_providers? Happy to test and leave feedback.

jashby44 avatar Aug 04 '21 14:08 jashby44

Hi @jashby44, we don't have a pre-release build, however you should be able to build it locally from main, although I wouldn't recommend running in production as there are still some known bugs.

manicminer avatar Aug 08 '21 23:08 manicminer

There are now APIs for creating AD B2C tenants programmatically, so is the "upstream" issue tag fixed, or is it still pending the Azure SDK for Go?

jrasanen avatar Sep 17 '21 10:09 jrasanen

@jrasanen Thanks for pointing this out! As this is a Resource Manager API, the corresponding resource to create/manage a B2C tenant and it's subscription association will be implemented in the AzureRM provider. The AzureAD provider will implement any resources which can be managed via Microsoft Graph (or potentially any future B2C-specific APIs), to manage the constructs within a B2C tenant.

I have opened an issue to track this: https://github.com/hashicorp/terraform-provider-azurerm/issues/13396

manicminer avatar Sep 17 '21 11:09 manicminer

Linked or not: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_policy

Does the above allow for the definition of custom policies via their own XML files?

@hhao01-becls the microsoft graph client has apparently been upgraded to support the upload of policies. It is used in Github action workflows, which sound like an acceptable alternative if terraform cannot write these custom policies.

helvetia-regel avatar Sep 06 '22 12:09 helvetia-regel

Hi @manicminer! Would you be open to accept a PR for adding support for B2C Userflow resource to this provider https://learn.microsoft.com/en-us/graph/api/resources/b2cidentityuserflow?view=graph-rest-beta ?

I see that azuread uses https://github.com/manicminer/hamilton/tree/main/msgraph as the Microsoft Graph API client but the client doesn't support B2C UserFlow related graph APIs. Would it be okay to integrate microsoftgraph/msgraph-beta-sdk-go https://github.com/microsoftgraph/msgraph-beta-sdk-go/tree/main/identity/b2cuserflows which has the required API support?

jarifibrahim avatar Sep 17 '22 06:09 jarifibrahim

@jarifibrahim We would definitely like to support this, however we are first looking to implement support in the provider for pinning, or otherwise asserting, the API version - due to this resource only being available in the beta API at this time.

We are not currently looking to use the official SDK(s).

manicminer avatar Sep 20 '22 08:09 manicminer

@manicminer is there an ETA on how long would it take to add support for pinning a version?

We are not currently looking to use the official SDK(s).

May I ask why? I am happy to add support for user flows to https://github.com/manicminer/hamilton/tree/main/msgraph as well.

Edit: Created https://github.com/manicminer/hamilton/pull/179 for adding B2C User Flow API support.

jarifibrahim avatar Sep 20 '22 17:09 jarifibrahim

Is there any possibility to create User Flows and generic OIDC Identity Providers in a B2C tenant at this time?

ghost avatar Oct 27 '22 16:10 ghost

@manicminer I saw a PR for user flow that got incorrectly marked as being released in version 2.35 but it was apparently never merged, any reason why that one was closed? I was looking forward to it. Can you shed some light on the status, please? AFAIC support is there in the hamilton library

ilmax avatar Apr 15 '23 08:04 ilmax

@ilmax Great question! Apologies, I closed that PR but forgot to update the milestone or post an explanatory comment. I've added that now, please see https://github.com/hashicorp/terraform-provider-azuread/pull/1009#issuecomment-1513891386

manicminer avatar Apr 18 '23 23:04 manicminer

Azure AD B2C will probably be superseded by Entra External ID for customers in the future and it looks like most of the effort goes into that instead of AD B2C. Also, Entra ID for customers seems to have proper APIs for configuration and fortunately dropped the whole Identity Experience Framework in favour of a more modern hook system called authentication extensions. Therefor I think this issue can be closed and a new one for "Entra External ID for customers support" could be created.

itpropro avatar Sep 07 '23 14:09 itpropro