@@ -77,8 +77,9 @@ def encode_access_token(identity, secret, algorithm, expires_delta, fresh,
7777 json_encoder = json_encoder )
7878
7979
80- def encode_refresh_token (identity , secret , algorithm , expires_delta , csrf ,
81- identity_claim_key , json_encoder = None ):
80+ def encode_refresh_token (identity , secret , algorithm , expires_delta , user_claims ,
81+ csrf , identity_claim_key , user_claims_key ,
82+ json_encoder = None ):
8283 """
8384 Creates a new encoded (utf-8) refresh token.
8485
@@ -88,15 +89,23 @@ def encode_refresh_token(identity, secret, algorithm, expires_delta, csrf,
8889 :param expires_delta: How far in the future this token should expire
8990 (set to False to disable expiration)
9091 :type expires_delta: datetime.timedelta or False
92+ :param user_claims: Custom claims to include in this token. This data must
93+ be json serializable
9194 :param csrf: Whether to include a csrf double submit claim in this token
9295 (boolean)
9396 :param identity_claim_key: Which key should be used to store the identity
97+ :param user_claims_key: Which key should be used to store the user claims
9498 :return: Encoded refresh token
9599 """
96100 token_data = {
97101 identity_claim_key : identity ,
98102 'type' : 'refresh' ,
99103 }
104+
105+ # Don't add extra data to the token if user_claims is empty.
106+ if user_claims :
107+ token_data [user_claims_key ] = user_claims
108+
100109 if csrf :
101110 token_data ['csrf' ] = _create_csrf_token ()
102111 return _encode_jwt (token_data , expires_delta , secret , algorithm ,
@@ -129,8 +138,8 @@ def decode_jwt(encoded_token, secret, algorithm, identity_claim_key,
129138 if data ['type' ] == 'access' :
130139 if 'fresh' not in data :
131140 raise JWTDecodeError ("Missing claim: fresh" )
132- if user_claims_key not in data :
133- data [user_claims_key ] = {}
141+ if user_claims_key not in data :
142+ data [user_claims_key ] = {}
134143 if csrf_value :
135144 if 'csrf' not in data :
136145 raise JWTDecodeError ("Missing claim: csrf" )
0 commit comments