Created
January 13, 2022 13:14
-
-
Save shlyk/dc9a15041e079a1c63648f6e04fd6f54 to your computer and use it in GitHub Desktop.
Firebase exchange a refresh token for an ID token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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