I am implementing a Django REST API with React. I followed this tutorial and fits perfectly as my requirement.
As per the code implementation from the tutorial,
def jwt_decode_token(token):
header = jwt.get_unverified_header(token)
jwks = requests.get(
settings.SOCIAL_AUTH_AUTH0_DOMAIN + "/.well-known/jwks.json"
).json()
public_key = None
for jwk in jwks["keys"]:
if jwk["kid"] == header["kid"]:
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(jwk))
if public_key is None:
raise Exception("Public key not found.")
issuer = settings.SOCIAL_AUTH_AUTH0_DOMAIN + "/"
return jwt.decode(
token,
public_key,
audience=settings.SOCIAL_AUTH_AUTH0_AUDIENCE,
issuer=issuer,
algorithms=["RS256"],
)
it seems we don’t use the decode_token method that the package provided.
All the access tokens got from the SPA using getAccessTokenSilently() to authenticate my custom API, apparently, all are working. The function invokes with every new page refresh.
Also, the docs say…
By default, an access token for a custom API is valid for 86400 seconds (24 hours).
So I assume that’s why both are working. What will be the workaround if I don’t want the last token to remain to validate.