@@ -62,6 +62,25 @@ def _generate_headers(self):
62
62
""":rtype dict: Additional headers to include in the JWT, defaults to an empty dict"""
63
63
return {}
64
64
65
+ @classmethod
66
+ def _from_jwt (cls , headers , payload , key = None ):
67
+ """
68
+ Class specific implementation of from_jwt which should take jwt components and return
69
+ and instance of this Class with jwt information loaded.
70
+ :return: Jwt object containing the headers, payload and key
71
+ """
72
+ jwt = Jwt (
73
+ secret_key = key ,
74
+ issuer = payload .get ('iss' , None ),
75
+ subject = payload .get ('sub' , None ),
76
+ algorithm = headers .get ('alg' , None ),
77
+ valid_until = payload .get ('exp' , None ),
78
+ nbf = payload .get ('nbf' , None ),
79
+ )
80
+ jwt .__decoded_payload = payload
81
+ jwt .__decoded_headers = headers
82
+ return jwt
83
+
65
84
@property
66
85
def payload (self ):
67
86
if self .__decoded_payload :
@@ -110,25 +129,6 @@ def to_jwt(self, algorithm=None, ttl=None):
110
129
111
130
return jwt_lib .encode (payload , self .secret_key , algorithm = algorithm , headers = headers )
112
131
113
- @classmethod
114
- def _from_jwt (cls , headers , payload , key = None ):
115
- """
116
- Class specific implementation of from_jwt which should take jwt components and return
117
- and instance of this Class with jwt information loaded.
118
- :return: Jwt object containing the headers, payload and key
119
- """
120
- jwt = Jwt (
121
- secret_key = key ,
122
- issuer = payload .get ('iss' , None ),
123
- subject = payload .get ('sub' , None ),
124
- algorithm = headers .get ('alg' , None ),
125
- valid_until = payload .get ('exp' , None ),
126
- nbf = payload .get ('nbf' , None ),
127
- )
128
- jwt .__decoded_payload = payload
129
- jwt .__decoded_headers = headers
130
- return jwt
131
-
132
132
@classmethod
133
133
def from_jwt (cls , jwt , key = '' ):
134
134
"""
0 commit comments