You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cookies set by the SDK (i.e. set in response to reading the X-Auth-Token header in case of frontend and Hanko API running on different domains) are not valid for subdomains. If my frontend runs on yourapp.com and I have another API running at api.yourapp.com then the cookie will only be valid for yourapp.com but not the api subdomain. This is because we do not set the domain attribute on creating the cookie:
_setAuthCookie(token: string){constsecure=!!this.api.match("^https://");Cookies.set(this.authCookieName,token,{ secure });// <- no domain set}
The Domain attribute specifies which hosts can receive a cookie. If the server does not specify a Domain, the browser defaults the domain to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included.
I think it is a viable scenario that users run another service on such a subdomain and want to use the JWT for authentication with said service as well.
Checklist
Description
Cookies set by the SDK (i.e. set in response to reading the
X-Auth-Token
header in case of frontend and Hanko API running on different domains) are not valid for subdomains. If my frontend runs onyourapp.com
and I have another API running atapi.yourapp.com
then the cookie will only be valid foryourapp.com
but not theapi
subdomain. This is because we do not set thedomain
attribute on creating the cookie:From MDN:
I think it is a viable scenario that users run another service on such a subdomain and want to use the JWT for authentication with said service as well.
Describe your ideal solution
Set the domain when creating the cookie:
How to get the domain at this point:
Workarounds or alternatives
No response
Hanko Version
v0.5.0
Additional Context
No response
The text was updated successfully, but these errors were encountered: