@@ -77,8 +77,9 @@ def encode_access_token(identity, secret, algorithm, expires_delta, fresh,
77
77
json_encoder = json_encoder )
78
78
79
79
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 ):
82
83
"""
83
84
Creates a new encoded (utf-8) refresh token.
84
85
@@ -88,15 +89,23 @@ def encode_refresh_token(identity, secret, algorithm, expires_delta, csrf,
88
89
:param expires_delta: How far in the future this token should expire
89
90
(set to False to disable expiration)
90
91
: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
91
94
:param csrf: Whether to include a csrf double submit claim in this token
92
95
(boolean)
93
96
: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
94
98
:return: Encoded refresh token
95
99
"""
96
100
token_data = {
97
101
identity_claim_key : identity ,
98
102
'type' : 'refresh' ,
99
103
}
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
+
100
109
if csrf :
101
110
token_data ['csrf' ] = _create_csrf_token ()
102
111
return _encode_jwt (token_data , expires_delta , secret , algorithm ,
@@ -129,8 +138,8 @@ def decode_jwt(encoded_token, secret, algorithm, identity_claim_key,
129
138
if data ['type' ] == 'access' :
130
139
if 'fresh' not in data :
131
140
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 ] = {}
134
143
if csrf_value :
135
144
if 'csrf' not in data :
136
145
raise JWTDecodeError ("Missing claim: csrf" )
0 commit comments