-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh token with complex object #100
Comments
if we look at access_token = encode_access_token(
identity=self._user_identity_callback(identity),
secret=config.encode_key,
algorithm=config.algorithm,
expires_delta=expires_delta,
fresh=fresh,
user_claims=self._user_claims_callback(identity),
csrf=config.csrf_protect,
identity_claim=config.identity_claim
) Where if we look at refresh_token = encode_refresh_token(
identity=self._user_identity_callback(identity),
secret=config.encode_key,
algorithm=config.algorithm,
expires_delta=expires_delta,
csrf=config.csrf_protect,
identity_claim=config.identity_claim
) if we add user_claims=self._user_claims_callback(identity), then we can pass user claim from refresh token to new token, otherwise we loose that information. |
In most cases, people would solve this by pulling their whole @auth.route('/refresh', methods=['POST'])
@jwt_refresh_token_required
def refresh():
refresh_user = User(get_jwt_identity(), None)
user = UserObject(refresh_user.username, refresh_user.roles)
ret = {
'access_token': create_access_token(identity=user),
}
return jsonify(ret), 200 I could potentially look at adding a flag that would keep the claims on both the access and refresh tokens, but unless I am missing something I imagine that wouldn't be very useful for the common case. Would the above example work for your case? |
hi everyone, would my example be a valid use case for this feature? our API authentication is using third-party service and storing some needed information in the token because the call is quite heavy...we wanted to use refreshing of that token to avoid the need to make that call every few minutes when the access token expires which is obviously not possible if the refresh token needs to get all info again... |
It sounds like this is a feature people want and would actually use. I'm in the middle of moving so it will likely be a couple weeks before I could get to this, but if someone else wanted to take a stab at it I would be happy to help out and get it merged. I'm thinking it should be an option so that we don't break backwords compatibility ( |
Released in version 3.10.0. Thanks for the PR @roubaeli! 👍 |
Hello everyone,
I am trying to do is refresh token with complex object. My code is as follows:
If I log in using my username and password, login function works just fine, I get my refresh token and access token. then If I hit
protected
endpoint, it works fine, it prints me all roles that I have store.However, if I hit
refresh
endpoint, then hitprotected
endpoint, I don't see any roles printed. I believe when I try to connect torefresh
endpoint. I loose all role related data. when I print(get_jwt_claims()), it doesn't print anything inrefresh
end point.If I am not wrong, when I hist
refresh
endpoint then it is looking for roles base upon refresh token. which is null and that is creating issue.The text was updated successfully, but these errors were encountered: