Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Comprobar permisos en FastAPI + Stawberry GraphQL

Estoy usando el decorador BasePermission como se especifica en la documentación .

 @strawberry.type class Query: @strawberry.field(permission_classes=[IsAuthenticated]) def user(self) -> User: # get by token OFC return User(user_id=1, email="vladimir@cw.tech", first_name = "Vladimir", last_name = "Kirilov")

En mi implementación, uso la clase VerifyToken como se describe en la documentación de FastAPI auth0.

 class IsAuthenticated(BasePermission): message = "User is not authenticated" def has_permission(self, source: Any, info: Info, **kwargs) -> bool: print(source) print(info) token: str = Depends(token_auth_scheme) print(token) result = VerifyToken(token.credentials).verify() if result.get("status"): print(result) return False return True

Entonces, estoy tratando de obtener y verificar el PORTADOR de la solicitud, pero no puedo extraerlo para procesarlo más y obtener el error, por favor avise.

 { "data": null, "errors": [ { "message": "'Depends' object has no attribute 'credentials'", "locations": [ { "line": 2, "column": 3 } ], "path": [ "user" ] } ] }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Lo descubrí, no de la manera más limpia, pero aquí está

 class IsAuthenticated(BasePermission): message = "User is not authenticated" async def has_permission(self, source: Any, info: Info, **kwargs) -> bool: request: Union[Request, WebSocket] = info.context["request"] print(request.headers) if "Authorization" in request.headers: print(request.headers['Authorization']) result = VerifyToken( request.headers['Authorization'][7:] ).verify() if result.get("status") == "error": print(result.get("msg")) return False if result.get("sub"): print(result) return True return False
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!