easyauth
easyauth copied to clipboard
Update token expiry or refresh token
How i can refresh google auth token ? If the user is active , i want to refresh the token and update the token expiry. If in get_user i check the token time and call issue token again , will it work?
` def get_user_handler(request: Request): if "token" not in request.cookies and "Authorization" not in request.headers: return None
if "token" in request.cookies and request.cookies['token'] != "INVALID":
token = request.cookies['token']
user_id = get_user_from_token(token)
//Here i will check the expiry and if the expiry is less than 5 mins will call **self.issue_token(permissions)**
return user_id
elif "Authorization" in request.headers:
# header should be separated by 'Bearer <tokenstr>'
decoded_token = jwt.decode(
request.headers["Authorization"].split(" ")[1],
options={"verify_signature": False},
)
return decoded_token["permissions"]["users"][0]
return None
return Depends(get_user_handler)`
@aghure that is one way to accomplish this manually, but if you want this to automatically be updated in cookies, you'll need to specify that in the response headers manually. I think adapting a simple refresh token endpoint could also be quite easy,
- [ ] - Add /token/refresh endpoint that re-issues a new token if passed a currently valid & unexpired token for a given user. The endpoint could also attempt to update the token in cookies at this time.