Title: Merge helper function to get current user integrated with the JWT plugin · Issue #34 · anomaly/lab-python-server · GitHub
Open Graph Title: Merge helper function to get current user integrated with the JWT plugin · Issue #34 · anomaly/lab-python-server
X Title: Merge helper function to get current user integrated with the JWT plugin · Issue #34 · anomaly/lab-python-server
Description: The FastAPI-JWT plugin provides a basic usage example which demonstrates using the Authorize: AuthJWT = Depends() dependency to get a handle on the JWT plugin instance, and then use the Authorize.jwt_required() function to protect endpoi...
Open Graph Description: The FastAPI-JWT plugin provides a basic usage example which demonstrates using the Authorize: AuthJWT = Depends() dependency to get a handle on the JWT plugin instance, and then use the Authorize.j...
X Description: The FastAPI-JWT plugin provides a basic usage example which demonstrates using the Authorize: AuthJWT = Depends() dependency to get a handle on the JWT plugin instance, and then use the Authorize.j...
Opengraph URL: https://github.com/anomaly/lab-python-server/issues/34
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Merge helper function to get current user integrated with the JWT plugin","articleBody":"The [FastAPI-JWT plugin](https://indominusbyte.github.io/fastapi-jwt-auth/usage/basic/) provides a basic usage example which demonstrates using the `Authorize: AuthJWT = Depends()` dependency to get a handle on the JWT plugin instance, and then use the `Authorize.jwt_required()` function to protect endpoints.\r\n\r\nSince we will be doing this across the application, the following utility function could wrap the entire process up and ultimately return the currently logged in user:\r\n\r\n```python\r\nasync def get_current_user(session:\r\n AsyncSession = Depends(get_async_session),\r\n Authorize: AuthJWT = Depends()\r\n):\r\n \"\"\"\r\n \"\"\"\r\n Authorize.jwt_required()\r\n current_user_email = Authorize.get_jwt_subject()\r\n\r\n user = await User.get_by_email(session, current_user_email)\r\n\r\n if not user:\r\n raise HTTPException(status_code=404, detail=\"User not found\")\r\n\r\n return user\r\n```\r\n\r\na demonstration of using it in the `/me` endpoint\r\n\r\n```python\r\n@router.get(\"/me\",\r\n response_model=UserResponse,\r\n operation_id=\"who_am_i\"\r\n)\r\nasync def get_me(request: Request,\r\n Authorize: AuthJWT = Depends(),\r\n current_user = Depends(get_current_user),\r\n session: AsyncSession = Depends(get_async_session)):\r\n \"\"\"Get the currently logged in user or myself\r\n\r\n This endpoint will return the currently logged in user or raise\r\n and exception if the user is not logged in.\r\n \"\"\"\r\n return current_user\r\n```\r\n\r\nThis example was developed as part of the first application developed using this template and we should merge these ideas into the base template","author":{"url":"https://github.com/devraj","@type":"Person","name":"devraj"},"datePublished":"2022-08-11T03:57:11Z","url":"https://github.com/anomaly/lab-python-server/issues/34"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e75520ce-5b4d-9ad3-f286-071f6fd9a51f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E54:1978BF:EE1C:1356D:6B047CB8 |
| html-safe-nonce | 54d8713abad5163b156e956b3327c3f7b72d5ab395e841f3cfe57d643f9fd7a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTU0OjE5NzhCRjpFRTFDOjEzNTZEOjZCMDQ3Q0I4IiwidmlzaXRvcl9pZCI6IjE4MTIzNjkyNzMyMDE2NTQ5NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 833a52ae31f2d7441017d239baa621b716d27d317265a8425caad79b80a3fb12 |
| hovercard-subject-tag | issue:1335439073 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/anomaly/lab-python-server/34/issue_layout |
| twitter:image | https://opengraph.githubassets.com/417e0b5f105f1759c3fe9aaeca29c4848ca48661276d1dee4bf3e9b6d5e2e8d8/anomaly/lab-python-server/issues/34 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/417e0b5f105f1759c3fe9aaeca29c4848ca48661276d1dee4bf3e9b6d5e2e8d8/anomaly/lab-python-server/issues/34 |
| og:image:alt | The FastAPI-JWT plugin provides a basic usage example which demonstrates using the Authorize: AuthJWT = Depends() dependency to get a handle on the JWT plugin instance, and then use the Authorize.j... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devraj |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366ddfb372682a32e92a5d86155cb08fa83e5bbe79953a968789f2f7e24c511 |
| turbo-cache-control | no-preview |
| go-import | github.com/anomaly/lab-python-server git https://github.com/anomaly/lab-python-server.git |
| octolytics-dimension-user_id | 3654837 |
| octolytics-dimension-user_login | anomaly |
| octolytics-dimension-repository_id | 491764445 |
| octolytics-dimension-repository_nwo | anomaly/lab-python-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 491764445 |
| octolytics-dimension-repository_network_root_nwo | anomaly/lab-python-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ed3f2e01f6b7672780c586c8af0e72726374d7b6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width