capawesome-team / capacitor-firebase

⚡️ Firebase plugins for Capacitor. Supports Android, iOS and the Web.
https://capawesome.io/plugins/firebase/
Apache License 2.0
405 stars 102 forks source link

feat: Implement the getIdTokenResult() function or an alternative #730

Open MrBasque opened 1 month ago

MrBasque commented 1 month ago

Plugin(s)

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' 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

robingenz commented 1 month ago

Yes, this method is not yet available. Would you be willing to create a PR?

MrBasque commented 1 month ago

Sure, will give it a go asap.