0

.netcore 6 project, Getting jwt from identity server, which looks fine in jwt.io

HEADER:

{
  "alg": "RS256",
  "kid": "4716390B357D1DA43908ABA78925B3A2",
  "typ": "at+jwt"
}

PAYLOAD:

{
  "iss": "http://....com",
  "nbf": 1693215898,
  "iat": 1693215898,
  "exp": 1693219498,
  "FirstName": "UserName",
  "given_name": "UserMidName",
  "family_name": "UserLastname",
  "client_id": "EP_Mobile_App",
  "aud": "backend.api"
}

I put this into Authorization header as Bearer token, Did this many times never encounter such difficulty, identity server teams says its ok every app validates it cool.

But I cant figure out whats wrong at my end or how to detect the issue here is config

        builder.Services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
        }).AddJwtBearer(options =>
        {
            options.RequireHttpsMetadata = false;
            options.Authority = "http://....com";
            options.Audience = "backend.api";
            options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = false,
                ValidateAudience = false,
                ValidateIssuerSigningKey = false,
                ValidateLifetime = false,
                ValidIssuer = "http://....com"
            };
        });

controller;

using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;

public class GetBookList : EndpointBaseAsync
            .WithRequest<string>
            .WithActionResult
    {
        #region Methods

        [Authorize]
        [HttpGet("api/[namespace]/Bundle")]
        public override async Task<ActionResult> HandleAsync([FromQuery] string request, CancellationToken cancellationToken = default)
        {

        }

        #endregion Methods
    }

always getting 401, what should be wrong here?

TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96
  • I suggest you could try to enable the trace logs to see why the token failed. Or ask identity server to see if which option you should set inside the builder.Services.AddAuthentication – Brando Zhang Aug 28 '23 at 10:41

0 Answers0