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
We are integrating with a 3rd party custom auth server that uses JWT tokens to validate the session.
We would like to have a way to pass the 3rd party JWT token to the session so it can be used in serverpod to do api call to the 3rd party on behalve of the user that is logged in.
login
register
profile
change password
delete account
are all handled by the 3rd party.
Right now it is only possible to save the token during login in the database and retreive it when doing one of these calls. I'm not really a fan because this puts the responsability on the server instead of token storage on the mobile device itself.
Proposal
It would be cool to have a field called extraData on Session so we can save all kind of data in there.
Use Case
The extra data could contain the following
a 3rd party auth token
a custom user role
user data we want to have available at any time
Alternatives
We could adapt all our request to pass the token which will make the api a lot harder to use.
Additional context
No response
How experienced are you with this library?
Intermediate - Familiar with the basics or have used it in a few projects
We have discussed adding an additional Map to the AuthenticationInfo object that is returned as a result from a successfull authentication, defined here:
It is available on Session under the authenticated property.
If I understand you correctly, you have implemented your own authenticationHandler and having the possibility to populate the AuthenticationInfo object with additional information satisfy your usecase?
As a temporary workaround, you could populate the dynamic userObject field on Session to store any information that should be associated with the authenticated user.
With that clarification, I think I might have misunderstood your request.
You are saying that you have additional information available on the client, which is not the auth token used to authenticate towards server, that should be included with every request.
Is that a more accurate description of the feature you are requesting?
I assumed that the information was already available in the token used to authenticate with to the server, if so, the information could simply have been taken out during the normal authentication flow for the token.
3RD PARTY AUTH SERVICE: Login in validated on 3rd party auth service
3RD PARTY AUTH SERVICE: Returns 3rd party token & 3rd party refresh token
SERVERPOD: Creates a "serverpod auth key" and returns a response like this that also includes the 3rd party token & 3rd party refresh token
MOBILE: Stores the serverpod auth key & 3rd party token & 3rd party refresh token
Any other API call
MOBILE: Performs a request
MOBILE: Adds the serverpod auth key & 3rd party token & 3rd party refresh token to that request
SERVERPOD: Validates the session at the 3rd party service
3RD PARTY AUTH SERVICE: Validates if the 3rd party token is still valid. If not a 401 is returned.
SERVERPOD: returns the correct data is the token was valid, if the token was invalid a 401 was returned
MOBILE: If the correct data was returned & a valid token was there, show the data in the app. If a 401 was returned try to reresh
Refresh:
MOBILE: Performs refresh api call (with refresh token)
SERVERPOD: calls the 3RD PARTY AUTH SERVICE to refresh the token with the token provided by mobile.
3RD PARTY AUTH SERVICE: Validates the token. & returns new token & refresh token if valid. otherwise return 401
SERVERPOD: Creates a "serverpod auth key" and returns a response like this that also includes the 3rd party token & 3rd party refresh token
All of this should happen automatically by serverpod from the moment I returned the "auth key + extra data"
Other concepts like JWT:
A similar concept i there with jwt tokens. you can add data to a jwt token on serverside that is always in there, from the moment the data is removed, or someone tried to temper with the jwt tokens are invalid
In the end it should be possible to add extra data to a token when loggin in that is passed to every request. In my case it is the 3rd party token
Can I conclude that this information should then be integrated with the token issued by Serverpod?
In short, you would like to have the possibility to add optional additional information to any auth key created by the Serverpod authentication module before it is sent and saved in the client. That information should then be available during authenticating requests to the server?
I have a related problem (I think) where this could come in to play.
Consider the case where the same authenticated user ([email protected] using gmail auth), can log on to two or more different organizations. In one org (say Acme) Bob is an admin. In another org (Coyote), Bob is a regular user.
The session object should reflect the org that bob is trying to log in to. The client must present the choice at login (Acme or Coyote?), but once Bob has logged in, the session should reflect the correct context. So the endpoint logic should be able to query the session for this info to make the correct authZ decisions.
Can I conclude that this information should then be integrated with the token issued by Serverpod?
In short, you would like to have the possibility to add optional additional information to any auth key created by the Serverpod authentication module before it is sent and saved in the client. That information should then be available during authenticating requests to the server?
Activity
SandPod commentedon Jan 14, 2025
We have discussed adding an additional
Mapto theAuthenticationInfoobject that is returned as a result from a successfull authentication, defined here:serverpod/packages/serverpod/lib/src/authentication/authentication_info.dart
Line 13 in e1fae90
It is available on
Sessionunder theauthenticatedproperty.If I understand you correctly, you have implemented your own
authenticationHandlerand having the possibility to populate theAuthenticationInfoobject with additional information satisfy your usecase?vanlooverenkoen commentedon Jan 14, 2025
Ah yes indeed this is probably what I need! I will do the implementation tomorrow and let you know if it fully fit's all usecases I described.
vanlooverenkoen commentedon Jan 14, 2025
Ah sorry I thought it was already implemented. But yes what you proposed is correct!
I have my own authenticationHandler indeed.
SandPod commentedon Jan 15, 2025
As a temporary workaround, you could populate the dynamic
userObjectfield on Session to store any information that should be associated with the authenticated user.vanlooverenkoen commentedon Jan 15, 2025
When should that happen? When the "3rd party token" is created during login? Or at every api call insert the "3rd party token"?
Because I don't want to store the "3rd party token" in the serverpod database. I want to have that on the users phone/device. Is that possible?
SandPod commentedon Jan 16, 2025
With that clarification, I think I might have misunderstood your request.
You are saying that you have additional information available on the client, which is not the auth token used to authenticate towards server, that should be included with every request.
Is that a more accurate description of the feature you are requesting?
I assumed that the information was already available in the token used to authenticate with to the server, if so, the information could simply have been taken out during the normal authentication flow for the token.
vanlooverenkoen commentedon Jan 16, 2025
So basicly this is what I need
Login:
3rd party token&3rd party refresh token3rd party token&3rd party refresh tokenserverpod auth key&3rd party token&3rd party refresh tokenAny other API call
serverpod auth key&3rd party token&3rd party refresh tokento that request3rd party tokenis still valid. If not a 401 is returned.Refresh:
3rd party token&3rd party refresh tokenAll of this should happen automatically by serverpod from the moment I returned the "auth key + extra data"
Other concepts like JWT:
A similar concept i there with jwt tokens. you can add data to a jwt token on serverside that is always in there, from the moment the data is removed, or someone tried to temper with the jwt tokens are invalid
In the end it should be possible to add extra data to a token when loggin in that is passed to every request. In my case it is the
3rd party tokenSandPod commentedon Jan 16, 2025
Thank you for the clarification!
Can I conclude that this information should then be integrated with the token issued by Serverpod?
In short, you would like to have the possibility to add optional additional information to any auth key created by the Serverpod authentication module before it is sent and saved in the client. That information should then be available during authenticating requests to the server?
vanlooverenkoen commentedon Jan 16, 2025
Exactly!!
wstrange commentedon Jan 23, 2025
I have a related problem (I think) where this could come in to play.
Consider the case where the same authenticated user ([email protected] using gmail auth), can log on to two or more different organizations. In one org (say Acme) Bob is an admin. In another org (Coyote), Bob is a regular user.
The session object should reflect the org that bob is trying to log in to. The client must present the choice at login (Acme or Coyote?), but once Bob has logged in, the session should reflect the correct context. So the endpoint logic should be able to query the session for this info to make the correct authZ decisions.
Hope that makes sense...
marcelomendoncasoares commentedon Mar 27, 2026
Closing as completed since this is possible using the callbacks to attach metadata to tokens on the new auth.