Requesting offline_access scope with Azure OAuth and Astro causes cookies to be deleted #766
Closed
2 tasks done
Labels
bug
Something isn't working
Bug report
Describe the bug
Using Azure as an OAuth provider for a single tenant application but I get the same problem on my multi-tenant & public minimal reproduction.
Have configured my app registration for the
offline_access
scopeSign in and cookie storage works perfectly fine when I don't request the
offline_access
scope. The access and refresh tokens are stored in my browser as 2 chunks.I want to query the MS Graph API, so I want the provider refresh token.
The cookie chunks are set like normal, I can see them actually set when I throttle the network or log them, they just get deleted after navigation, redirect or refresh. The Set-Cookie headers appear as follows upon navigation, redirect or refresh:
Without
offline_access
, the Set-Cookie headers re-set the access and refresh tokens (actual token redacted, but it's there):Cookie options for the above are:
Max-Age=31536000000; Path=/; SameSite=Lax
offline_access
, theprovider_token
andprovider_refresh_token
are present in the initial callback Set-Cookie header where thesb-<project_id>-auth-token-code-verifier
cookie is deleted. This cookie is broken up into 3 chunks, rather than 2. When redirected from callback to the next page, the request headers contain the 3 chunks and the response header contains the sanitised version without the provider/provider refresh tokens in 2 chunks.Upon navigation, redirect or refresh, the next request header contains the 2 sanitised chunks, and also the original 3rd chunk - this leads to a malformed cookie when the chunks are combined - I guess this is why the Set-Cookie response header deletes them.
To Reproduce
Create an empty Astro ^4.5 project with Supabase SSR 0.1.0, the Astro Vercel adapter, Tailwind and micromatch
pages/index.astro
:pages/nextpage.astro
: <--- here you can see that the cookies are being set, but they've disappeared from Application > Cookiespages/otherpage.astro
helper.ts
:middleware/index.ts
:pages/api/auth/signin.ts
:pages/api/auth/callback.ts
:signout.ts
:.env
:Expected behavior
The cookies should be retained in both instances (requesting
offline_access
and not).Screenshots
N/A
System information
Additional context
See my minimal example
The text was updated successfully, but these errors were encountered: