capacitor-firebase icon indicating copy to clipboard operation
capacitor-firebase copied to clipboard

feat: Implement the getIdTokenResult() function or an alternative

Open MrBasque opened this issue 4 months ago • 2 comments

Plugin(s)

  • [ ] Analytics
  • [ ] App
  • [ ] App Check
  • [X] Authentication
  • [ ] Crashlytics
  • [ ] Cloud Firestore
  • [ ] Cloud Functions
  • [ ] Cloud Messaging
  • [ ] Cloud Storage
  • [ ] Performance
  • [ ] Remote Config

Current problem

We are exploring your FirebaseAuthentication plugin, but we are missing the ability to retrieve the custom claims from the token.

The original firebase/auth contains a 'getIdTokenResult() : Promise<IdTokenResult>' function that does return the user claims.

Preferred solution

Implement the a way to retrieve the entire token like described in Additional context, or at least a possibility to return the custom claims.

Alternative options

No response

Additional context

This is the firebase/auth IdTokenResult interface :

export declare interface IdTokenResult {
    /**
     * The authentication time formatted as a UTC string.
     *
     * @remarks
     * This is the time the user authenticated (signed in) and not the time the token was refreshed.
     */
    authTime: string;
    /** The ID token expiration time formatted as a UTC string. */
    expirationTime: string;
    /** The ID token issuance time formatted as a UTC string. */
    issuedAtTime: string;
    /**
     * The sign-in provider through which the ID token was obtained (anonymous, custom, phone,
     * password, etc).
     *
     * @remarks
     * Note, this does not map to provider IDs.
     */
    signInProvider: string | null;
    /**
     * The type of second factor associated with this session, provided the user was multi-factor
     * authenticated (eg. phone, etc).
     */
    signInSecondFactor: string | null;
    /** The Firebase Auth ID token JWT string. */
    token: string;
    /**
     * The entire payload claims of the ID token including the standard reserved claims as well as
     * the custom claims.
     */
    claims: ParsedToken;
}

Before submitting

  • [X] I have read and followed the feature request guidelines.
  • [X] I have attached links to possibly related issues and discussions.

MrBasque avatar Sep 27 '24 20:09 MrBasque