0

I have an Authentication Server application (AuthServer) using OpenIdDict. And a client application (ClientApp) which has a simple controller action:

Startup client configuration:

builder.Services
 .AddAuthentication(o => { o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; })
 .AddCookie()
 .AddOAuth("OpenIddict.Server.AspNetCore", o => { 
 o.AuthorizationEndpoint = new Uri($"{AuthenticationServerUrl}connect/authorize").AbsoluteUri;
 o.TokenEndpoint = new Uri($"{AuthenticationServerUrl}connect/token").AbsoluteUri;
 o.ClientId = "testoauth";
 o.ClientSecret = "testsecret";
 o.CallbackPath = new PathString("/callback/login/local");
 o.UsePkce = true;
 });

The client controller action:

[HttpGet("oauth")]
[Authorize(AuthenticationSchemes = "OpenIddict.Server.AspNetCore")]
public IActionResult OAuth2() => Ok($"Successfully authorized with authorizationcode flow.");

I think it has something todo with the cookie: ".AspNetCore.Identity.Application". It is not created somehow using Postman. I see that the Cookie is created in the browser dev-tools. Postman generates the access_token successfully. But is not added to the cookies collection.

Fix: After creation of the access_token, Postman is not added this cookie to the request header. It can be found in the Console section of Postman, so add it manually. Do the request again and the action will be called.

asked Mar 11, 2025 at 14:28
3
  • May I know what is your problem now? Or what trapped you? Commented Mar 12, 2025 at 3:31
  • 1
    @TinyWang Never mind, I found my answer. The issue was that the .AspNetCore.Identity.Application cookie was not automatically added to the Postman cookies. So I manually added the cookie to the Postman cookies collection. This cookie can be found in the Postman console when generating the access_token. Commented Mar 13, 2025 at 6:46
  • Please post the fix as an answer - don't edit it into the question itself. Commented Mar 13, 2025 at 19:14

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.