https://supertokens.com/ logo
Getting access token
j

Jrapp

04/21/2023, 3:36 PM
Hey team, I'm using a custom third party oauth integration and I have it working, but I need to be able to get the third party's accessToken to make requests to their API. Is it possible to get this access token from the session? Im using Next and checked the
req.session.*
values but it doesnt seem to be stored in there
r

rp

04/21/2023, 3:38 PM
Hey @Jrapp which recipe are you using?
j

Jrapp

04/21/2023, 3:38 PM
Specifically the
ThirdParty
recipe
Added a custom OAuth integration for Discord
r

rp

04/21/2023, 3:39 PM
See this page
j

Jrapp

04/21/2023, 3:39 PM
That is just to be used at sign up though right?
Im wondering how I can retrieve it at any point an authenticated user makes a request to the backend
r

rp

04/21/2023, 3:46 PM
You could add it to the session’s access token payload
Using session.mergeIntoAccessTokenPayload function.
j

Jrapp

04/21/2023, 3:47 PM
đź‘Ť This would also have to happen when the access token refreshes right? Is there a middleware that this logic could live?
r

rp

04/21/2023, 3:48 PM
The access token retains its payload even after refresh
If you want to refresh the provider’s access token, then you can do that by saving the refresh token of the provider as well, and then overriding the refresh function in the session recipe to use the refresh token.
j

Jrapp

04/21/2023, 3:50 PM
ohhh okay so it sounds like SuperTokens wont handle refreshing the providers accessToken?
r

rp

04/21/2023, 3:50 PM
Correct.
But you can do the refreshing yourself as mentioned above
j

Jrapp

04/21/2023, 3:51 PM
Okay, any useful docs / guides I can follow for this? The refreshing seems straightforward, Im more curious about the session.mergeIntoAccessTokenPayload function
The response object in the signinup override has the session object
j

Jrapp

04/21/2023, 5:37 PM
Is there a way to update that payload outside of that function? If the accessToken needs to get refreshed I'll have to update the payload of the session with the new access token
r

rp

04/21/2023, 5:39 PM
i don't quite understand
j

Jrapp

04/21/2023, 8:43 PM
No probem I was able to get it all working. Thanks for the help!