Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7dbaeabbb
|
|||
0911a73085
|
|||
1de73e99e3
|
|||
b44af0658a
|
24
auth.py
24
auth.py
@ -30,13 +30,20 @@ class PasswordMismatchException(Exception):
|
||||
|
||||
UserEntry = namedtuple('UserEntry', ['id', 'login', 'expiry', 'claims'])
|
||||
|
||||
|
||||
JWT_PRIV_KEY = ""
|
||||
with open('/opt/app/config/authservice.key', 'r') as f:
|
||||
JWT_PRIV_KEY = f.read()
|
||||
try:
|
||||
JWT_PRIV_KEY = os.environ["JWT_PRIV_KEY"]
|
||||
except KeyError:
|
||||
with open('/opt/app/config/authservice.key', 'r') as f:
|
||||
JWT_PRIV_KEY = f.read()
|
||||
|
||||
JWT_PUB_KEY = ""
|
||||
with open('/opt/app/config/authservice.pub', 'r') as f:
|
||||
JWT_PUB_KEY = f.read()
|
||||
try:
|
||||
JWT_PUB_KEY = os.environ["JWT_PUB_KEY"]
|
||||
except KeyError:
|
||||
with open('/opt/app/config/authservice.pub', 'r') as f:
|
||||
JWT_PUB_KEY = f.read()
|
||||
|
||||
|
||||
def getUserEntryFromDB(application: str, login: str):
|
||||
@ -106,7 +113,8 @@ def generateToken(**args):
|
||||
"iss": JWT_ISSUER,
|
||||
"iat": int(timestamp),
|
||||
"exp": int(timestamp + userEntry.expiry),
|
||||
"sub": str(userEntry.id)
|
||||
"sub": str(userEntry.id),
|
||||
"aud": application
|
||||
}
|
||||
for claim in userEntry.claims.items():
|
||||
# print("DEBUG: generateToken: add claim {} -> {}".format(claim[0], claim[1]))
|
||||
@ -129,8 +137,10 @@ def generateToken(**args):
|
||||
print("ERROR: generateToken: unspecific exception: {}".format(str(e)))
|
||||
raise werkzeug.exceptions.Unauthorized()
|
||||
|
||||
def generateTokenFromEnc(content):
|
||||
return content
|
||||
def generateTokenFromEnc(**args):
|
||||
cryptContent = args["body"]
|
||||
raise werkzeug.exceptions.NotImplemented("Stay tuned, will be added soon")
|
||||
return str(cryptContent)
|
||||
|
||||
def getPubKey():
|
||||
return JWT_PUB_KEY
|
||||
|
9
testjwe.py
Normal file
9
testjwe.py
Normal file
@ -0,0 +1,9 @@
|
||||
from jose import jwe
|
||||
|
||||
|
||||
JWT_PUB_KEY = os.environ["JWT_PUB_KEY"]
|
||||
|
||||
plainText = "BlaBlaBla123"
|
||||
cryptText = jwe.encrypt(plainText, JWT_PUB_KEY, "A256GCM", "RSA-OAEP")
|
||||
|
||||
print(cryptText)
|
Reference in New Issue
Block a user