Skip to content

Instantly share code, notes, and snippets.

@shlyk
Created January 13, 2022 13:14
Show Gist options
  • Save shlyk/dc9a15041e079a1c63648f6e04fd6f54 to your computer and use it in GitHub Desktop.
Save shlyk/dc9a15041e079a1c63648f6e04fd6f54 to your computer and use it in GitHub Desktop.
Firebase exchange a refresh token for an ID token
import axios from "axios";
import { Auth } from "firebase-admin/auth";
export const getIdToken = async (auth: Auth, uid: string) => {
const customToken = await auth.createCustomToken(uid);
const res = await axios.post(
`http://localhost:[PORT]/www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=[KEY]`,
{
token: customToken,
returnSecureToken: true,
}
);
return res.data.idToken;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment