File tree 1 file changed +8
-1
lines changed
ydb/oauth2_token_exchange
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 10
10
except ImportError :
11
11
jwt = None
12
12
13
+ try :
14
+ from cryptography .hazmat .primitives .serialization import load_pem_private_key
15
+ except ImportError :
16
+ load_pem_private_key = None
17
+
13
18
14
19
class Token (abc .ABC ):
15
20
def __init__ (self , token : str , token_type : str ):
@@ -48,6 +53,7 @@ def __init__(
48
53
token_ttl_seconds : int = 3600 ,
49
54
):
50
55
assert jwt is not None , "Install pyjwt library to use jwt tokens"
56
+ assert load_pem_private_key is not None , "Install cryptography library to use jwt tokens"
51
57
self ._signing_method = signing_method
52
58
self ._key_id = key_id
53
59
if private_key and private_key_file :
@@ -70,6 +76,7 @@ def __init__(
70
76
raise Exception ("JWT: no private key specified" )
71
77
if self ._token_ttl_seconds <= 0 :
72
78
raise Exception ("JWT: invalid jwt token TTL" )
79
+ self ._loaded_private_key = load_pem_private_key (self ._private_key .encode (), password = None )
73
80
74
81
def token (self ) -> Token :
75
82
now = time .time ()
@@ -96,7 +103,7 @@ def token(self) -> Token:
96
103
headers ["kid" ] = self ._key_id
97
104
98
105
token = jwt .encode (
99
- key = self ._private_key ,
106
+ key = self ._loaded_private_key ,
100
107
algorithm = self ._signing_method ,
101
108
headers = headers ,
102
109
payload = payload ,
You can’t perform that action at this time.
0 commit comments