C
C#5mo ago
bogdanstefan

OAuth - Failed to retrieve access token.

Hello there. I am trying to play around with the OAuth concept and with the "authorization code" flow in .NET 6. Therefore, I have a simple and custom authorization server which exposes the "/oauth/authorization" and "/oauth/token" endpoints. On the other side, I have a simple MVC client in which I have a single controller with a single endpoint protected with the [Authorize] attribute. I am using a cookie for the authentication and signing in which is supposed to hold the access token. If no cookie is present, then I am starting the authentication flow to get the access token. However, it seems that after the OAuth middleware gets past the "/oauth/authorization" endpoint, reaches the "/oauth/token" endpoint and obtains the access token, returns the "Failed to retrieve access token." error message, that I can see it in the client console. I've attached some pictures with the code. What am I doing wrong? Also, instead of returning a 200 OK status with the access token appended to it, I tried to append it to the response body with "await Response.Body.WriteAsync(bytes_of_serialized_accessToken_object);" and Redirect to the "redirect_uri", but I get a "StatusCode cannot be set because the response has already started" on the server side. Can someone please, help and shed some light on what I am doing wrong? Thank you!
No description
No description
4 Replies
Anton
Anton5mo ago
I think you have to use the public key from the key you used for signing to verify the token
bogdanstefan
bogdanstefanOP5mo ago
Hmm. Any suggestion on how should I do that?
Anton
Anton5mo ago
you seem to just generate the key and throw it away use the same key then pass the same key to authentication
bogdanstefan
bogdanstefanOP5mo ago
I understand. I am just trying to figure out how to use in the client app and the AddOAuth() middleware.
Want results from more Discord servers?
Add your server