Skip to content

Commit e9e58d4

Browse files
committed
test: jwt token
1 parent 32d1ba9 commit e9e58d4

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ the output should be: `{"data":{"type":"test","id":"1","attributes":{"message":"
9999
```bash
100100
curl -X GET "http://localhost:8000/v1/inference/epfl/neo4j" \
101101
-H "accept: application/json" \
102-
-H "Authorization: Bearer YOUR_TOKEN"
102+
-H "Authorization: Bearer YOUR_TOKEN" \
103+
103104
```
104105

105106
#### Inference

src/inference_api.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ def verify_jwt(credentials: HTTPAuthorizationCredentials = Depends(security)):
2323
print(token)
2424
header = jwt.get_unverified_header(token)
2525
print(header)
26-
try:
27-
claims = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
28-
if claims.get("service") != "airflow":
29-
raise HTTPException(status_code=403, detail="Invalid service identity")
30-
return claims
31-
except JWTError as e:
32-
print("JWT decode error:", e)
33-
raise HTTPException(status_code=403, detail="Invalid token")
26+
claims = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
27+
if claims.get("service") != "airflow":
28+
raise HTTPException(status_code=403, detail="Invalid service identity")
29+
else:
30+
print("valid claims")
31+
return claims
32+
# try:
33+
# claims = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
34+
# if claims.get("service") != "airflow":
35+
# raise HTTPException(status_code=403, detail="Invalid service identity")
36+
# return claims
37+
# except JWTError as e:
38+
# print("JWT decode error:", e)
39+
# raise HTTPException(status_code=403, detail="Invalid token")
3440

3541

3642
@app.get("/v1/test")

0 commit comments

Comments
 (0)