angular 15 + azure b2c
See original GitHub issuei’m using the above techs to port as a poc an old app. login to b2c is done in angular, using code flow, and it returns a complete set of data ( access token, custom roles etc).
i’m now trying to protect an endpoint by using eg:
public override void Configure()
{
Claims("sub");
Post("/users/getuserbyid");
//Policies("LoggedIn");
}
or by setting up a policy in program.cs:
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("LoggedIn", x => x.RequireClaim("sub"));
});
builder.Services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(o =>
{
o.Authority = $"https://xxxxx.b2clogin.com/xxxxx.onmicrosoft.com/B2C_1_signin/v2.0";
o.Audience = "xxxx-xxxx-xxxx-xxxx";
});
the call from angular looks like:
const options = { headers: new HttpHeaders({
Authorization: 'Bearer ' + this.accessToken,
Accept: 'application/json, text/plain, */*'
}),
params: new HttpParams().set("Id", id)};
return this.http.post<T>(this.apiBaseUrl + url, options);
}
and my request object server-side looks like:
public class EntityByIdRequest
{
[From(Claim.name, IsRequired = true)]
public string name { get; set; }
public string Id { get; set; } = string.Empty;
}
nothing works. i am never authenticated and i never get the id i pass in the params object in the request, unless i remove the authorization restriction. i’m obv. missing something, but what? any ideas anyone?
Issue Analytics
- State:
- Created 8 months ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Configure authentication in a sample Angular SPA by ...
Configure authentication in a sample Angular single-page application by using Azure Active Directory B2C · Step 1: Configure your user flow · Step ......
Read more >Enable authentication in an Angular application by using ...
This configuration file contains information about your Azure AD B2C identity provider and the web API service. The Angular app uses this ...
Read more >Tutorial: Create an Angular app that uses the ...
MSAL Angular enables Angular 9+ applications to authenticate enterprise users by using Azure Active Directory (Azure AD), and also users ...
Read more >Authenticate Angular App using Azure AD B2C
The objective of this post is to give the readers a practical understanding of Azure AD B2C by authenticating an Angular application using...
Read more >Angular 15 support · Issue #5410 · AzureAD/microsoft- ...
Public Description Will MSAL support Angular 15. M.. ... stopped me dead in my tracks after promoting azure B2C and Angular. hard to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…sorted. although the api was declaring my jwt as valid, including validating the audience, i had an incorrect audience setting. i did a few other minor changes but afaict that was the main issue. thanks again for your help.
if all else fails, do a minimalistic repro using asp.net minimal apis according to their tutorials/guides and i’ll help to convert that to fastendpoints.