Blazor webassembly bypassing IdentityServer ABP 3.3 RC1
Hi I am trying to use Azure Ad B2C for authentication without much success. I I tried the repurpose the article for Azure AD and MVC but there are key differences with Blazor since we have to connect to the host api for permission.
I got as far as login in with B2C but once I try to make a call to an protected API, I get not authorized 401. I know that I have a bearer token on the Blazor side, but on the Host side it does not seem to trigger the authorization call.
I even tried to add a OnTokenValided to see if the the token validation even takes place but the event never triggers.
How does the Blazor Client authorizes with the Host API?
Is there something I am missing here?
Just to clarify, I tried both external Identity with Identity server and direct connect to Azure AD B2C
I am in a similar position - but trying to use Azure AD from this article.
The article point to a FAQ page which itself has more info and a link to the abp-samples.
Unfortunately none of the sample pertaining to what we are trying to achieve here have been written targeting the template project for Blazor/ separate ids4 host.
Hopefully we can get a quick demo up using the latest preview release simply using the BookStore sample, but use Azure AD.
For now I can repurpose the code in the Host project (HttpApiHostModule) but it has the draw back of not retaining the uername for the Audit columns in any FullAuditEntity.
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Add("sub", ClaimTypes.NameIdentifier);
context.Services.AddAuthentication()
.AddOpenIdConnect("AzureOpenId", "Azure AD OpenId", options =>
{
options.Authority = "https://login.microsoftonline.com/" + configuration["AzureAd:TenantId"] + "/v2.0/";
options.ClientId = configuration["AzureAd:ClientId"];
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.CallbackPath = configuration["AzureAd:CallbackPath"];
options.ClientSecret = configuration["AzureAd:ClientSecret"];
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("email");
});
context.Services.AddAuthentication()
.AddJwtBearer(options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = false;
options.Audience = "Gp";
options.BackchannelHttpHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
});
}
just a comment - you can't really bypass IDS4 entirely as it holds Authorization info needed by the app. Azure AD is used to establish the Identity of the user - which is a good thing as we don't need to be the keeper of passwords for our apps.
@274188A thank you for your comments. I finally got this to work however I think it is flaky in the current state. For example: I still need to figure how to not have two login pages for customer (/authentication/login then press a button) Then there is the issue of the register popup after sign in for the first time which can be a security risk in multitenant applications
Here is a scenario
- I create a tenant1 and a tenant2
- I login with a user which exists in B2C but does not yet exist in ABP
- User gets presented a register page and the user can pick tenant1 or tenant 2 and ABP will essentially give access to the user to whatever tenant he picked
How I plan to fix this
- Make changes to the Account module so that when I create a user inside a tenant, I also call the Azure graph api to create the user in AD B2C
- Add the Object ID from B2C in the ABPUserLogins table along with the TenantID, the Provider Key, etc
- Override the register page to check the APBUserLogins table and automatically log in the user in the correct tenant
I think this will help with a better user sign in for
Last thing is to figure how not to have to pick the tenant from the form and get this in DB
After further playing with this it seems like the best thing to do let identity server authenticate externally then use this authentication to log in the user with Identity server. If I need the claim from Azure AD B2C, I think there is a way to save the claims but with Graph API you can always get it back.