Replies: 1 comment 3 replies
-
Using a cookie for a web api seems a poor choice. How should an api respond to a missing or invalid cookie? It can't redirect a client application to a login page, it can only return an "Unauthorized" HTTP error status, and hope the client will try again. Also, api calls need to be generated by application code, and so the client browser has no role in adding this cookie to the request automatically. Here, you are really treating the cookie as an authentication token, and so using a token-based approach seems preferable. JWT is the obvious choice, and makes it clear which api endpoint is responsible for generating the token (e.g., a "login" mutation in HotChocolate), and that the token must be stored and included in the subsequent api calls by the application code. This also allows the token creation to be handled by a completely different system (i.e., single-sign on) and the api to trust tokens issued by this system. The token can include all the necessary claims to authorize access to the data based on the user. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to enable cookie authentication with HC. Here is my current setup:
For
OnRedirectToLogin
to get called, a login route must be specified. How would I do this with HC?Beta Was this translation helpful? Give feedback.
All reactions