@rueben.tiow I did have audience in the params.
Here’s my code for login and for login using socials.
auth_response = requests.post(
f"https://{self.AUTH0_DOMAIN}oauth/token",
json={
"grant_type": "password",
"client_id": self.AUTH0_CLIENT_ID,
"client_secret": self.AUTH0_CLIENT_SECRET,
"username": email_address,
"password": password,
"connection": self.AUTH0_CONNECTION,
"audience": f"https://{self.AUTH0_DOMAIN}api/v2/",
"scope": "openid profile email offline_access",
},
)
token_url = f"https://{self.AUTH0_DOMAIN}oauth/token"
payload = {
"grant_type": "authorization_code",
"client_id": self.AUTH0_CLIENT_ID,
"client_secret": self.AUTH0_CLIENT_SECRET,
"code": code,
"redirect_uri": redirect_to,
"connection": self.AUTH0_CONNECTION,
"audience": f"https://{self.AUTH0_DOMAIN}api/v2/",
"scope": "openid profile email offline_access",
}
response = requests.post(token_url, json=payload)
And then to decode the token, I am using JWKs as:
unverified_header = jwt.get_unverified_header(token)
kid = unverified_header["kid"]
public_key = Auth0().get_public_key(kid)
auth0_domain = f"https://{Settings().auth0_domain}"
audience = f"https://{Settings().auth0_domain}api/v2/"
payload = jwt.decode(
token,
public_key,
algorithms=["RS256"],
audience=audience,
issuer=auth0_domain,
)
auth0_user_id = payload.get("sub")
The access_token from username and password is decoded and returns user id but from social login, I am unable to decode and it gives this error:
kid = unverified_header[“kid”] KeyError: ‘kid’
I then printed the unverified_header for
- social login: {‘alg’: ‘dir’, ‘enc’: ‘A256GCM’, ‘iss’: ‘https://dev-appid.au.auth0.com/’}
- username password login: {‘alg’: ‘RS256’, ‘typ’: ‘JWT’, ‘kid’: ‘kid_value’}
Let me know if I am doing anything wrong and how I should fix this issue.