KindeK
Kinde3y ago
48 replies
LIFE

Resolving auth in back-end (.NET) with token retrieved from front-end (React)

Hello, i have finished a setup in react, but i need to use the token to authenticate and authorize the user in the back-end. AFAIK there are no documents on Kinde elaborating on this issue, would anyone be able to support?

In .NET authentication is added:

var jwtIssuer = builder.Configuration.GetSection("Jwt:Issuer").Get<string>();

builder.Services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

})
 .AddJwtBearer(options =>
 {
    options.SaveToken = true;
     options.TokenValidationParameters = new TokenValidationParameters
     {
     ValidIssuer = jwtIssuer,
     };
 });


but the access_token is always null

        [HttpGet]
        public async Task<IActionResult> C()
        {
            var a = HttpContext.User;
            var accessToken = await HttpContext.GetTokenAsync("access_token");
            return Ok("test B");
        }
Was this page helpful?