A function to extract the authorization token from a user request, extract the user details and propagate them to the current security manager, if any.
(request: Request)
| 14 | |
| 15 | |
| 16 | async def inject_user_details(request: Request) -> Any: |
| 17 | """ |
| 18 | A function to extract the authorization token from a user request, extract the user details and propagate them to the |
| 19 | current security manager, if any. |
| 20 | """ |
| 21 | sm = get_security_manager() |
| 22 | current_user = None |
| 23 | if sm is not None: |
| 24 | try: |
| 25 | auth_manager = get_auth_manager() |
| 26 | access_token = auth_manager.token_extractor.extract_access_token( |
| 27 | request=request |
| 28 | ) |
| 29 | if not access_token: |
| 30 | raise HTTPException( |
| 31 | status_code=401, detail="Missing authentication token" |
| 32 | ) |
| 33 | |
| 34 | current_user = ( |
| 35 | await auth_manager.token_parser.user_details_from_access_token( |
| 36 | access_token=access_token |
| 37 | ) |
| 38 | ) |
| 39 | |
| 40 | sm.set_current_user(current_user) |
| 41 | except Exception: |
| 42 | raise HTTPException( |
| 43 | status_code=401, detail="Invalid or expired access token" |
| 44 | ) |
| 45 | |
| 46 | return current_user |
nothing calls this directly
no test coverage detected