Platform: C#, Visual Studio ASP.NET 2.1 Core
I am trying to POST a form to a controller, and am using the AuthHttp service to make the post inside of a service:
create(volunteer) { return this.authHttp.post(this.volunteerEndpoint + '/CreateVolunteer', volunteer) .map(result => result.json()); }
Inside of my startup.cs file, I have the standard code in ConfigureServices:
services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = "https://mydomain.auth0.com/"; options.Audience = "https://api.mydomain.com/"; });
along with the app.UseAuthentication() call in Configure.
Inside of auth.service.ts, I initialize the authentication.
auth0 = new auth0.WebAuth({ clientID: AUTH_CONFIG.clientID, domain: 'auth.mydomain.tech', responseType: 'token id_token', audience: `https://${AUTH_CONFIG.domain}/userinfo`, redirectUri: AUTH_CONFIG.callbackURL, scope: 'openid email profile' });
With the following variables
export const AUTH_CONFIG: AuthConfig = {
clientID: âxxxClientIDStringxxxâ,
domain: âmydomain.auth0.comâ,
callbackURL: âhttp://localhost:62659/â
};
In the controller, I have post with the authorize tag
[HttpPost("CreateVolunteer")] [Authorize] public async Task<IActionResult> CreateVolunteer([FromBody] VolunteerSaveResource volunteerResource) { if (!ModelState.IsValid) return BadRequest(ModelState); ---- code ---- return Ok(result); }
When I call the controller, I get the error from postman : WWW-Authenticate âBearer error=âinvalid_tokenâ, error_description=âThe audience is invalidâ
I have read documentation, and I think the problem is that my the aut from the token doesnât match the audience, but I think I have some fundamental misunderstanding of how to make that right. If I grab the HAR of the request, I see the bearer, and decoding it, I get aud equaling the xxxClientIDStringxxx as above.
So, is my problem in the startup.cs file, with the audience that I have specified? What is the relationship between the API and the Application? Do I need to somehow specify an audience there that is the same as the Application?