|
17 | 17 |
|
18 | 18 | import daiquiri |
19 | 19 | import httpx |
| 20 | +from iam_lib.api.api_key import ApiKeyClient |
20 | 21 | from iam_lib.api.edi_token import EdiTokenClient |
21 | 22 | from iam_lib.exceptions import IAMResponseError, IAMInvalidToken |
22 | 23 | import ssl |
@@ -50,11 +51,28 @@ async def authenticate(request: Request) -> tuple: |
50 | 51 | truststore=Config.CA_FILE |
51 | 52 | ) |
52 | 53 |
|
| 54 | + api_key_client = ApiKeyClient( |
| 55 | + scheme=Config.AUTH_SCHEME, |
| 56 | + host=Config.AUTH_HOST, |
| 57 | + accept=Config.ACCEPT_TYPE, |
| 58 | + public_key_path=Config.AUTH_PUBLIC_KEY, |
| 59 | + algorithm=Config.JWT_ALGORITHM, |
| 60 | + token=None, |
| 61 | + truststore=Config.CA_FILE |
| 62 | + |
| 63 | + ) |
| 64 | + |
53 | 65 | if ((auth_token is None) and (edi_token is not None)) or ((auth_token is not None) and (edi_token is None)): |
54 | 66 | msg = "EDI token and PASTA token must be present together" |
55 | 67 | raise InvalidTokenException(msg, status.HTTP_400_BAD_REQUEST) |
56 | 68 | elif auth_token is None and edi_token is None: |
57 | | - if "authorization" in request.headers: |
| 69 | + if "key" in request.query_params: |
| 70 | + key = request.query_params["key"] |
| 71 | + api_key_response = api_key_client.key_to_token(key=key) |
| 72 | + auth_token = api_key_response["pasta-token"] |
| 73 | + pasta_token.from_auth_token(auth_token) |
| 74 | + edi_token = api_key_response["edi-token"] |
| 75 | + elif "authorization" in request.headers: |
58 | 76 | basic_auth = request.headers["authorization"] |
59 | 77 | auth_token, edi_token = await ldap_authenticate(basic_auth) |
60 | 78 | pasta_token.from_auth_token(auth_token) |
|
0 commit comments