New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Token checker function not working #19
Comments
techxonia
changed the title
Token helper function not working
Custom Token helper function not working
Nov 7, 2020
techxonia
changed the title
Custom Token helper function not working
Custom Token checker function not working
Nov 7, 2020
You return error, not return ex. check your code again when I testing in my machine is working @app.get('/user')
def user(Authorize: AuthJWT = Depends()):
try:
current_user = jwt_token_checker(Authorize)
except Exception as ex:
return ex # return ex not error
return {"user": current_user}
def jwt_token_checker(Authorize: AuthJWT):
try:
Authorize.jwt_required()
return Authorize.get_jwt_subject()
except Exception as ex:
return ex # return ex not error |
Here is actual code: It is not working:
Helper Function:
|
you must raise an exception not return a response @app.get('/user')
async def user(Authorize: AuthJWT = Depends()):
try:
await jwt_token_checker(Authorize)
return {"success": True}
except Exception:
return JSONResponse(
status_code=200,
content={
"data": None,
"code": 400,
"message": "Some thing Went Wrong",
"status": False
}
)
async def jwt_token_checker(Authorize: AuthJWT):
try:
Authorize.jwt_required()
except AuthJWTException:
raise # raise exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I try to separate the logic of checking JWT tokens from one function so that it can be reused. But when I try to run the code, it does not work. I manage an access token in my database and check if it exists or not. The last generated token will be valid only for the access token. This access token must be checked at every protected endpoint. Here is my code:
Helper Function:
Is this right way to separate the token checker function? If not then can you please suggest me some solution.
The text was updated successfully, but these errors were encountered: