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

No "identities" property in ParseToken interface #6218

Closed
kyun opened this issue May 4, 2022 · 3 comments · Fixed by #6234 or #6298
Closed

No "identities" property in ParseToken interface #6218

kyun opened this issue May 4, 2022 · 3 comments · Fixed by #6234 or #6298

Comments

@kyun
Copy link

kyun commented May 4, 2022

[REQUIRED] Describe your environment

  • Operating System version: macOS Monterey 12.1
  • Browser version: Google Chrome 100.0.4896.127
  • Firebase SDK version: 9.6.10
  • Firebase Product: auth

[REQUIRED] Describe the problem

Steps to reproduce:

I've been using firebase v8, and yesterday I migrated v8 to v9.

With firebase v8, I used to get the userId below code.

user.getIdTokenResult().then(({ token, signInProvider, claims })=>{
  const info = claims.firebase;
  const [id] = info?.identities[signInProvider || ''];
  consoel.log('Here is my id', id);
});

but after upgrading to v9, I get a type error

Property 'identities' does not exist on type '{ sign_in_provider?: string | undefined; sign_in_second_factor?: string | undefined; }'.

For testing, I signed up using Twitter, and I got a ParsedToken.

and I printed that token on the console.

{
  aud: "####",
  auth_time: 123456,
  exp: 123456,
  firebase: {
    identities: { twitter.com: ["ID"] },
    sign_in_provider: "twitter.com",
  },
  iat: 123456,
  ...
}

identities is existed.

but there are no identities props in @firebase/auth/dist/auth-public.d.ts

/**
 * Interface representing a parsed ID token.
 *
 * @privateRemarks TODO(avolkovi): consolidate with parsed_token in implementation.
 *
 * @public
 */
export declare interface ParsedToken {
    /** Expiration time of the token. */
    'exp'?: string;
    /** UID of the user. */
    'sub'?: string;
    /** Time at which authentication was performed. */
    'auth_time'?: string;
    /** Issuance time of the token. */
    'iat'?: string;
    /** Firebase specific claims, containing the provider(s) used to authenticate the user. */
    'firebase'?: {
        'sign_in_provider'?: string;
        'sign_in_second_factor'?: string;
    };
    /** Map of any additional custom claims. */
    [key: string]: string | object | undefined;
}

I think it should be updated like this.

export declare interface ParsedToken {
    /* ... */
    'iat'?: string;
    /** Firebase specific claims, containing the provider(s) used to authenticate the user. */
    'firebase'?: {
        identities: {
          [key: string]: Array<IdTypeOfSomething>
        };
        'sign_in_provider'?: string;
        'sign_in_second_factor'?: string;
    };
    /** Map of any additional custom claims. */
    [key: string]: string | object | undefined;
}

I compare v8 to v9, and I've found why it happened.

In version 9

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;
}

claims defined as ParsedToken in v9,
but v8 is

interface IdTokenResult {
  /* ... */
  claims: {
    [key: string]: any;
  };
}
@kyun kyun changed the title No identities property in ParseToken interface No "identities" property in ParseToken interface May 4, 2022
@jbalidiong jbalidiong added the v9 label May 4, 2022
@sam-gc
Copy link
Contributor

sam-gc commented May 9, 2022

Thanks for the report @kyun, the linked PR fixes the issue -- it should be available soon (keep an eye on the release notes)

@marcusx2
Copy link

What are all the possible key values for an identity?

@kyun
Copy link
Author

kyun commented May 29, 2022

@marcusx2 I have no idea what are all the possible key values for identity because I had used it only with Twitter Auth.
In my case, twitter.com could be an identity key value. In other cases, I guess the Firebase team knows.

@firebase firebase locked and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants