Reputation: 21
I'm working on a user authentication in an Astro project (using SSR). I'm using auth-astro and followed this tutorial to do basic auth (it works): https://blog.otterlord.dev/posts/auth-astro/
However, I'd like to store user's refresh_token returned by Strava in the backend for nightly data pulls. I can't figure out how to access raw HTTP response from Strava, containing the access_token, refresh_token and athlete object. I managed to log what is supposed to be the token using this video: https://www.youtube.com/watch?v=fYObrr3jf0w , but it does not match Strava response schema:
Strava response schema:
{
"token_type": "Bearer",
"expires_at": 1568775134,
"expires_in": 21600,
"refresh_token": "e5n567567...",
"access_token": "a4b945687g...",
"athlete": {
#{summary athlete representation}
}
}
My auth.config.ts:
import Strava, { type StravaProfile } from '@auth/core/providers/strava'
import { defineConfig } from 'auth-astro'
export default defineConfig({
providers: [
Strava({
clientId: import.meta.env.STRAVA_CLIENT_ID,
clientSecret: import.meta.env.STRAVA_CLIENT_SECRET,
authorization: {
params: {
scope: `read,read_all,profile:read_all,activity:read,activity:read_all`
}}
}),
],
callbacks: {
async session({ session, token }) {
console.log(token)
session.user = token as any;
return session;
},
}
})
My logs:
17:31:35 [200] / 8ms
17:32:10 [watch] auth.config.ts
{
name: 'Tomasz Łyszczyk',
picture: 'https://lh3.googleusercontent.com/a/ACg8ocKSNH-BqDQkG0J-NwPaUFpjqDUf9MOF-YiufEJEfJD7g_c=s96-c',
sub: '64390882',
iat: 1704557624,
exp: 1707149624,
jti: 'acda374b-ccd5-4ac1-8691-683d83c8475d'
}
logowanie w index
{
user: {
name: 'Tomasz Łyszczyk',
picture: 'https://lh3.googleusercontent.com/a/ACg8ocKSNH-BqDQkG0J-NwPaUFpjqDUf9MOF-YiufEJEfJD7g_c=s96-c',
sub: '64390882',
iat: 1704557624,
exp: 1707149624,
jti: 'acda374b-ccd5-4ac1-8691-683d83c8475d'
},
expires: '2024-02-05T16:32:10.308Z'
}
17:32:10 [200] / 9ms
I tried to access refresh_token in response from Strava using auth-astro (auth.js), logging the token, but can't figure out where it is stored.
Upvotes: 1
Views: 242