Hotchocolate: Authorization with JWT

Created on 1 Oct 2019  ยท  6Comments  ยท  Source: ChilliCream/hotchocolate

When i used Web API , i used the attribute [Authorize] above the controller
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]

i have installed the Authorization package of hotchocolate.

I wonder how i can reach the same approach with
descriptor.Authorize();
in my overrided configuration method

how i can pass "AuthenticationSchemes " to the Authorize() method


I have another small question:
how i can fetch the Context ?

โ“ question

All 6 comments

Hot Chocolate provides directives for authorization but does not do authentication. The bearer schema has to be configured with authentication.

For authentication refer to the ASP.NET documentation.

Once you have setup authentication you can use use policies, roles or just the authenticated check provided by the authorize directives.

https://hotchocolate.io/docs/authorization

how i can fetch the Context ?

If you mean the HttpContext then register the IHttpContextAccessor and use dependency injection.

how i can fetch the Context ?

If you mean the HttpContext then register the IHttpContextAccessor and use dependency injection.

Thanks a lot for the help.

But, i have tried fetching the context with IHttpContextAccessor before i created this issue. unfortunately, not all properties are fetched !

for example the body stream, is not fetched !

What do you actually want to do?

well, i tried to catch the body as a stream

the body, i mean, the query itself

You cannot do that since the middleware has already consumed the body. You can however access the parsed body through the IResolverContext.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcin-janiak picture marcin-janiak  ยท  4Comments

RohrerF picture RohrerF  ยท  3Comments

nigel-sampson picture nigel-sampson  ยท  5Comments

nigel-sampson picture nigel-sampson  ยท  5Comments

IKolosynskyi picture IKolosynskyi  ยท  3Comments