MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / get_token

Function get_token

app/api/agentops/api/routes/v3.py:67–96  ·  view source on GitHub ↗

Authenticate and issue JWT token

(
    request: Request,
    body: TokenSchema,
    orm: Session = Depends(get_orm_session),
)

Source from the content-addressed store, hash-verified

65
66@router.post("/auth/token")
67async def get_token(
68 request: Request,
69 body: TokenSchema,
70 orm: Session = Depends(get_orm_session),
71) -> TokenResponse:
72 """Authenticate and issue JWT token"""
73 try:
74 api_key = UUID(body.api_key) # raises ValueError
75 project = ProjectModel.get_by_api_key(orm, api_key)
76
77 if not project:
78 raise InvalidAPIKeyError(403, "Invalid API key")
79
80 return TokenResponse(
81 token=generate_jwt(project),
82 project_id=project.id,
83 project_prem_status=project.org.prem_status.value,
84 )
85
86 except ValueError as e:
87 # api_key is not a valid UUID
88 logger.warning(f"Invalid API key format: {str(e)}")
89 return JSONResponse({"error": "Invalid API key format"}, status_code=400)
90 except InvalidAPIKeyError as e:
91 # project not found for the given api_key
92 logger.warning(f"Invalid API key: {str(e)}")
93 return JSONResponse({"error": str(e)}, status_code=e.code)
94 except Exception as e:
95 logger.error(f"Error authenticating: {str(e)}")
96 return JSONResponse({"error": "Authentication failed"}, status_code=500)
97
98
99@router.get("/auth/token")

Callers

nothing calls this directly

Calls 4

InvalidAPIKeyErrorClass · 0.90
generate_jwtFunction · 0.90
TokenResponseClass · 0.85
get_by_api_keyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…