Getting access token
# support-questions
j
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
Hey @Jrapp which recipe are you using?
j
Specifically the
ThirdParty
recipe
Added a custom OAuth integration for Discord
r
See this page
j
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
You could add it to the session’s access token payload
Using session.mergeIntoAccessTokenPayload function.
j
đź‘Ť This would also have to happen when the access token refreshes right? Is there a middleware that this logic could live?
r
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
ohhh okay so it sounds like SuperTokens wont handle refreshing the providers accessToken?
r
Correct.
But you can do the refreshing yourself as mentioned above
j
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
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
i don't quite understand
j
No probem I was able to get it all working. Thanks for the help!