Skip to content

Commit 32d1ba9

Browse files
committed
test: debug jwt
1 parent 3a6da53 commit 32d1ba9

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ the output should be: `{"data":{"type":"test","id":"1","attributes":{"message":"
9797
6. Try the inference endpoint:
9898

9999
```bash
100-
curl -X GET "http://localhost:8000/v1/inference/epfl/YOUR_DB" \
100+
curl -X GET "http://localhost:8000/v1/inference/epfl/neo4j" \
101101
-H "accept: application/json" \
102-
-H "Authorization: Bearer YOUR_JWT_TOKEN"
102+
-H "Authorization: Bearer YOUR_TOKEN"
103103
```
104104

105105
#### Inference

src/inference_api.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717

1818

1919
def verify_jwt(credentials: HTTPAuthorizationCredentials = Depends(security)):
20+
print(JWT_SECRET_KEY)
2021
token = credentials.credentials
2122
print("token")
2223
print(token)
23-
payload = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
24-
print("payload")
25-
print(payload)
26-
print("service: ", payload.get("service"))
24+
header = jwt.get_unverified_header(token)
25+
print(header)
2726
try:
28-
payload = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
29-
if payload.get("service") != "airflow":
27+
claims = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
28+
if claims.get("service") != "airflow":
3029
raise HTTPException(status_code=403, detail="Invalid service identity")
31-
return payload
30+
return claims
3231
except JWTError as e:
3332
print("JWT decode error:", e)
3433
raise HTTPException(status_code=403, detail="Invalid token")

src/utils/api_token.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@
2222

2323
# FOR RUNAI INFERENCE API
2424
print("All configurations for token in place:")
25-
print(JWT_SECRET_KEY, JWT_ALGORITHM)
26-
payload = {
25+
print(datetime.utcnow() + timedelta(hours=3))
26+
claims = {
2727
"sub": AIRFLOW_SUB,
2828
"service": AIRFLOW_SERVICE,
29-
"exp": datetime.utcnow() + timedelta(hours=1),
29+
"exp": datetime.utcnow() + timedelta(hours=3),
3030
"iat": datetime.utcnow(),
3131
}
32-
token = jwt.encode(payload, JWT_SECRET_KEY, algorithm=JWT_ALGORITHM)
32+
token = jwt.encode(claims, JWT_SECRET_KEY, algorithm=JWT_ALGORITHM)
3333
print("Validating token")
3434
credentials = HTTPAuthorizationCredentials(scheme="Bearer", credentials=token)
35-
print(credentials)
36-
payload = verify_jwt(credentials)
37-
print(payload)
35+
claims = verify_jwt(credentials)
36+
print(claims)
3837
print(f"Generated token: {token}")
3938

4039
# for AIRFLOW API
41-
# payload = {"username": AIRFLOW_USERNAME, "password": AIRFLOW_PASSWORD}
40+
# claims = {"username": AIRFLOW_USERNAME, "password": AIRFLOW_PASSWORD}
4241
# headers = {"Authorization": f"Bearer {token}"}
4342
# res = requests.get(INFERENCE_URL + f"/inference/{NEO4J_DATABASE}", headers=headers)

0 commit comments

Comments
 (0)