Skip to content

Authentication Support with Azure AD with B2C #342

Closed
@jaliyaudagedara

Description

@jaliyaudagedara

I couldn't get authentication to work with Azure AD B2C.

Upon looking at the code, we are using IdentityModel in the OAuth2TokenManager.

Unfortunately following line doesn't work with Azure AD B2C. discoveryDocument is going to contain an error.

var discoveryDocument = 
    await this.HttpClient.GetDiscoveryDocumentAsync(oauthProperties.Authority.ToString(), cancellationToken);

The error is, Endpoint belongs to different authority which is getting thrown from IdentityModel library.

And because of that, discoveryDocument.TokenEndpoint is going to be null here.

using var request = new HttpRequestMessage(HttpMethod.Post, new Uri(oauthProperties.Authority, discoveryDocument.TokenEndpoint))
{
    Content = new FormUrlEncodedContent(properties)
};

We can get past that error when using IdentityModel by doing something like below,

DiscoveryDocumentResponse discoveryDocument
    = await httpClient.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest
    {
        Address = "https://login.microsoftonline.com/<TenantId>/v2.0",
        Policy = new DiscoveryPolicy
        {
            AdditionalEndpointBaseAddresses =
            {
                "https://login.microsoftonline.com/<TenantId>",
		"https://graph.microsoft.com/oidc/userinfo"
            }
        }
    });

But OAuth2TokenManager isn't extendable.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions