Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4111d5

Browse files
committed
Reorder Jwt base class methods
1 parent 5d0c907 commit a4111d5

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

twilio/jwt/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ def _generate_headers(self):
6262
""":rtype dict: Additional headers to include in the JWT, defaults to an empty dict"""
6363
return {}
6464

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+
6584
@property
6685
def payload(self):
6786
if self.__decoded_payload:
@@ -110,25 +129,6 @@ def to_jwt(self, algorithm=None, ttl=None):
110129

111130
return jwt_lib.encode(payload, self.secret_key, algorithm=algorithm, headers=headers)
112131

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-
132132
@classmethod
133133
def from_jwt(cls, jwt, key=''):
134134
"""

0 commit comments

Comments
 (0)