Skip to content
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

[Feature]: Verify id tokens #9

Closed
Lxstr opened this issue Mar 12, 2023 · 5 comments
Closed

[Feature]: Verify id tokens #9

Lxstr opened this issue Mar 12, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@Lxstr
Copy link

Lxstr commented Mar 12, 2023

Is your proposal related to a problem?

Hi Asif, would be great to be able to use the function:
decoded_token = auth.verify_id_token(id_token)

Describe the solution you'd like.

Be able to acces the decoded token claims:
{
  'iss': 'https://securetoken.google.com/project-id',
  'aud': 'project-id',
  'auth_time': 1622574389,
  'user_id': 'abcdefgh1234567890',
  'sub': 'abcdefgh1234567890',
  'iat': 1622574390,
  'exp': 1622577990,
  'email': '[email protected]',
  'email_verified': True,
  'firebase': {
    'identities': {
      'email': ['[email protected]']
    },
    'sign_in_provider': 'password'
  }
}

Describe alternatives you've considered.

https://firebase.google.com/docs/auth/admin/verify-id-tokens#web

Additional context.

Trying to get the expiry timestamp in order to check if i need to refresh the users idToken. Then I would set up requirement to pass idToken as extra security layer

@Lxstr Lxstr added the enhancement New feature or request label Mar 12, 2023
@github-actions
Copy link

Hello @Lxstr , thank you for submitting an issue! A project committer will shortly review the issue.

@Lxstr Lxstr changed the title [Feature]: <Verify id tokens> [Feature]: Verify id tokens Mar 12, 2023
@AsifArmanRahman
Copy link
Owner

Hey @Lxstr.

I actually need your opinion on how this should be done. As mentioned here Verify ID tokens using a third-party JWT library, should I procced with all the checks to verify it? Or do it simply by retrieving the public key for the kid in the headers and verify it using the retrieved public key.

@Lxstr
Copy link
Author

Lxstr commented Mar 15, 2023

I wasn't sure if we had to actually verify it, I thought could just call the api and use the response, but I really have not much of an idea of what is correct here. I am only coming from perspective of a serverside app.

I managed to wrangle something from AI after some back an forth, could this be an option?


url = f"https://identitytoolkit.googleapis.com/v1/accounts:lookup?key={firebase_project_id}"

payload = {
    "idToken": id_token,
    "returnSecureToken": True
}

response = requests.post(url, data=json.dumps(payload))

if response.ok:
    user_info = response.json()["users"][0]
    decoded_token = base64.urlsafe_b64decode(id_token.split(".")[1] + "==").decode("utf-8")
    token_info = json.loads(decoded_token)
else:
    error_message = response.json()["error"]["message"]
    print(f"Error verifying ID token: {error_message}")

@AsifArmanRahman
Copy link
Owner

I haven't tested it yet, but by the looks of it, it seems like the v1 endpoint for Get Account Info which is used in get_account_info, and it doesn't return decoded claims stored in the id_token

@Lxstr
Copy link
Author

Lxstr commented Apr 30, 2023

Awesome, thanks for your hard work! Hopefully, this will be handy additional feature for people using the token passing feature. Although, in hindsight I'm not sure if using this as an extra layer in my case (server side) is truly needed so I'll maybe write about it and see if there's some feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants