Skip to content

Commit 023a8d1

Browse files
Add id_token if available.
1 parent d2253a4 commit 023a8d1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pharus/server.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,29 +223,33 @@ def login() -> dict:
223223
headers=headers,
224224
auth=auth,
225225
)
226-
encoded_jwt = result.json()["access_token"]
226+
auth_info = dict(
227+
jwt=result.json()["access_token"], id=result.json()["id_token"]
228+
)
227229
connect_creds = {
228230
"databaseAddress": request.args["database_host"],
229231
"username": jwt.decode(
230-
encoded_jwt,
232+
auth_info["jwt"],
231233
crypto_serialization.load_der_public_key(
232234
b64decode(environ.get("PHARUS_OIDC_PUBLIC_KEY").encode())
233235
),
234236
algorithms="RS256",
235237
options=dict(verify_aud=False),
236238
)[environ.get("PHARUS_OIDC_SUBJECT_KEY")],
237-
"password": encoded_jwt,
239+
"password": auth_info["jwt"],
238240
}
239241
else: # Database login
240242
# Generate JWT key and send it back
241-
encoded_jwt = jwt.encode(
242-
request.json, environ["PHARUS_PRIVATE_KEY"], algorithm="RS256"
243+
auth_info = dict(
244+
jwt=jwt.encode(
245+
request.json, environ["PHARUS_PRIVATE_KEY"], algorithm="RS256"
246+
)
243247
)
244248
connect_creds = request.json
245249
if connect_creds.keys() < {"databaseAddress", "username", "password"}:
246250
return dict(error="Invalid Request, check headers and/or json body")
247251
_DJConnector._attempt_login(**connect_creds)
248-
return dict(jwt=encoded_jwt)
252+
return dict(**auth_info)
249253
except Exception as e:
250254
return str(e), 500
251255

0 commit comments

Comments
 (0)