@@ -25,7 +25,7 @@ def _encode_jwt(additional_token_data, expires_delta, secret, algorithm):
25
25
26
26
27
27
def encode_access_token (identity , secret , algorithm , expires_delta , fresh ,
28
- user_claims , csrf ):
28
+ user_claims , csrf , identity_claim ):
29
29
"""
30
30
Creates a new encoded (utf-8) access token.
31
31
@@ -40,11 +40,12 @@ def encode_access_token(identity, secret, algorithm, expires_delta, fresh,
40
40
be json serializable
41
41
:param csrf: Whether to include a csrf double submit claim in this token
42
42
(boolean)
43
+ :param identity_claim: Which claim should be used to store the identity in
43
44
:return: Encoded access token
44
45
"""
45
46
# Create the jwt
46
47
token_data = {
47
- 'identity' : identity ,
48
+ identity_claim : identity ,
48
49
'fresh' : fresh ,
49
50
'type' : 'access' ,
50
51
'user_claims' : user_claims ,
@@ -54,7 +55,7 @@ def encode_access_token(identity, secret, algorithm, expires_delta, fresh,
54
55
return _encode_jwt (token_data , expires_delta , secret , algorithm )
55
56
56
57
57
- def encode_refresh_token (identity , secret , algorithm , expires_delta , csrf ):
58
+ def encode_refresh_token (identity , secret , algorithm , expires_delta , csrf , identity_claim ):
58
59
"""
59
60
Creates a new encoded (utf-8) refresh token.
60
61
@@ -65,18 +66,19 @@ def encode_refresh_token(identity, secret, algorithm, expires_delta, csrf):
65
66
(datetime.timedelta)
66
67
:param csrf: Whether to include a csrf double submit claim in this token
67
68
(boolean)
69
+ :param identity_claim: Which claim should be used to store the identity in
68
70
:return: Encoded refresh token
69
71
"""
70
72
token_data = {
71
- 'identity' : identity ,
73
+ identity_claim : identity ,
72
74
'type' : 'refresh' ,
73
75
}
74
76
if csrf :
75
77
token_data ['csrf' ] = _create_csrf_token ()
76
78
return _encode_jwt (token_data , expires_delta , secret , algorithm )
77
79
78
80
79
- def decode_jwt (encoded_token , secret , algorithm , csrf ):
81
+ def decode_jwt (encoded_token , secret , algorithm , csrf , identity_claim ):
80
82
"""
81
83
Decodes an encoded JWT
82
84
@@ -85,6 +87,7 @@ def decode_jwt(encoded_token, secret, algorithm, csrf):
85
87
:param algorithm: Algorithm used to encode the JWT
86
88
:param csrf: If this token is expected to have a CSRF double submit
87
89
value present (boolean)
90
+ :param identity_claim: expected claim that is used to identify the subject
88
91
:return: Dictionary containing contents of the JWT
89
92
"""
90
93
# This call verifies the ext, iat, and nbf claims
@@ -93,8 +96,8 @@ def decode_jwt(encoded_token, secret, algorithm, csrf):
93
96
# Make sure that any custom claims we expect in the token are present
94
97
if 'jti' not in data :
95
98
raise JWTDecodeError ("Missing claim: jti" )
96
- if 'identity' not in data :
97
- raise JWTDecodeError ("Missing claim: identity" )
99
+ if identity_claim not in data :
100
+ raise JWTDecodeError ("Missing claim: {}" . format ( identity_claim ) )
98
101
if 'type' not in data or data ['type' ] not in ('refresh' , 'access' ):
99
102
raise JWTDecodeError ("Missing or invalid claim: type" )
100
103
if data ['type' ] == 'access' :
0 commit comments