Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7dbaeabbb
|
|||
0911a73085
|
|||
1de73e99e3
|
|||
b44af0658a
|
|||
309b4c6ba8
|
|||
a921fb6a0f
|
|||
f56db65012
|
25
auth.py
25
auth.py
@ -30,15 +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()
|
||||
print("DEBUG PRIVKEY: {}".format(JWT_PRIV_KEY))
|
||||
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()
|
||||
print("DEBUG PUBKEY: {}".format(JWT_PUB_KEY))
|
||||
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):
|
||||
@ -108,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]))
|
||||
@ -131,5 +137,10 @@ def generateToken(**args):
|
||||
print("ERROR: generateToken: unspecific exception: {}".format(str(e)))
|
||||
raise werkzeug.exceptions.Unauthorized()
|
||||
|
||||
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
|
||||
|
19
openapi.yaml
19
openapi.yaml
@ -7,7 +7,7 @@ paths:
|
||||
/auth:
|
||||
post:
|
||||
tags: [ "JWT" ]
|
||||
summary: Return JWT token
|
||||
summary: Accept login and password, return JWT token
|
||||
operationId: auth.generateToken
|
||||
requestBody:
|
||||
content:
|
||||
@ -21,6 +21,23 @@ paths:
|
||||
'text/plain':
|
||||
schema:
|
||||
type: string
|
||||
/authe:
|
||||
post:
|
||||
tags: [ "JWT" ]
|
||||
summary: Accept encrypted set of credentials, return JWT token
|
||||
operationId: auth.generateTokenFromEnc
|
||||
requestBody:
|
||||
content:
|
||||
'text/plain':
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: JWT token
|
||||
content:
|
||||
'text/plain':
|
||||
schema:
|
||||
type: string
|
||||
/secret:
|
||||
get:
|
||||
tags: [ "JWT" ]
|
||||
|
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