11# coding: utf-8
22from __future__ import absolute_import , unicode_literals
33
4+ import os
45from datetime import datetime
56
67import jwt
@@ -125,6 +126,14 @@ def decode_jwt_token(token):
125126 return payload
126127
127128
129+ def read_key_file (file_name ):
130+ if api_settings .KEY_STORE_ROOT :
131+ file_path = os .path .abspath (os .path .join (api_settings .KEY_STORE_ROOT , file_name ))
132+ else :
133+ file_path = os .path .abspath (file_name )
134+ return open (file_path , 'rt' ).read ()
135+
136+
128137def get_private_key_and_key_id (issuer , key_id = None ):
129138 if not api_settings .PRIVATE_KEYS .get (issuer ):
130139 raise InvalidKeyError ('No private keys defined for the given issuer' )
@@ -133,7 +142,7 @@ def get_private_key_and_key_id(issuer, key_id=None):
133142 private_keys_setting = [private_keys_setting ]
134143 for pks in private_keys_setting :
135144 if not key_id or key_id == pks :
136- return open ( pks , 'rt' ). read ( ), pks
145+ return read_key_file ( file_name = pks ), pks
137146 raise InvalidKeyError ('No private key matches the given key_id' )
138147
139148
@@ -150,7 +159,7 @@ def get_public_key_and_key_id(issuer, key_id=None):
150159 public_keys_setting = [public_keys_setting ]
151160 for pks in public_keys_setting :
152161 if not key_id or key_id == pks :
153- return open ( pks , 'rt' ). read ( ), pks
162+ return read_key_file ( file_name = pks ), pks
154163 raise InvalidKeyError ('No public key matches the given key_id' )
155164
156165
0 commit comments