Search code examples
c#asp.net-web-apiopeniddict

Why grant_type is not in OpenIddictRequest parameters?


I have an endPoint service with the following prototype: async Task<IActionResult> Exchange(OpenIddictRequest openIdRequest) I send a postMan request like below: enter image description here

As you can see, I'm sending 4 parameters, and particulary I provide parameter grant_type with value password. But when I check the parameters in the back-end I just get 3 parameters like below:

enter image description here

When I check with openIdRequest.IsPasswordGrantType() method it returns false.

If I add a new parameter with name grantType and value password I get 4 paramters and the method openIdRequest.IsPasswordGrantType() returns true. You can see it in the following images:

enter image description here

And in the backend:

enter image description here

If I replace the parameter grant_type with parameter grantType I get this error:

openiddict the mandatory 'grant_type' parameter is missing

can anyone guide me please? (I'm using OpenIddict: version 3.1.1 and .net 6)


Solution

  • I found the problem. I changed the Exchange Method prototype from :

    Task<IActionResult> Exchange(OpenIddictRequest openIdRequest)
    

    to:

    Task<IActionResult> Exchange()
    

    and got the openIdRequest from HttpContext like below:

    var openIdRequest = HttpContext.GetOpenIddictServerRequest();
    

    Now I can see all of those parameters in my openIdRequest.