Skip to content

ParsedToken type does not support allowed value types in Firebase custom claims #6553

@briandonahue

Description

@briandonahue

[REQUIRED] Describe your environment

  • Operating System version: MacOS
  • Browser version: n/a
  • Firebase SDK version: 9.9.2
  • Firebase Product: auth

[REQUIRED] Describe the problem

When receiving an IdTokenResult for a user, the claims property is of type ParsedToken. This only provides for custom claim fields with the following signature:
[key: string]: string | object | undefined

But Firebase (and firebase-admin) support other types such as boolean and number. This results in confusion if you try to use a ParsedToken object as argument to match against custom claims. For example, my user can have the claim admin: true but that is invalid in a ParsedToken, you can only set admin: 'true' which does not match the boolean value.

I noticed this while using the reactfire library, as they use a ParsedToken to validate required claims.

Steps to reproduce:

1 - attempt to create a ParsedToken object with a boolean or numeric value.

Relevant Code:

const invalidClaims: ParsedToken = {
  admin: true, // not valid
  score: 500 // not valid
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions