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!
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!


