Firebase idToken中缺少Givenname和Familyname声明
原学程将引见Firebase idToken中缺乏Givenname以及Familyname申明的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。
成绩描写
我正在测验考试应用Firebase为我们的Web运用法式完成Google登录。
上面是我为夺取idToken所做的任务:
const 谷歌_provider = new GoogleAuthProvider();
谷歌_provider.addScope("openid");
谷歌_provider.addScope("profile");
谷歌_provider.addScope("email");
signInWithPopup(auth, 谷歌_provider).then((result) =>
result.user.getIdToken());
固然我曾经添减了设置装备摆设文件感化域,但是我依然没法取得idtoken
中的givenname
以及familyname
(email
、picture
以及name
是可用的)
(我测验考试直交应用Google登录,在那边我不妨瞅到一切小我材料申明)
我在这里错过了甚么?我做错了甚么吗?
推举谜底
由getIdToken()
前往的Firebase ID令牌没有包括您正在查找的用户的谷歌帐户信息(预期称号、小我材料图象等)。您应当应用从登录成果中检索到的拜访代码向Google API收回夺取它的要求。
signInWithPopup(auth, provider)
.then(async (result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const response = await fetch('https://www.谷歌apis.com/oauth二/v一/userinfo', {
headers: {
Authorization: `Bearer ${token}`
}
})
const data = await response.json();
console.log(data);
})
佳了闭于Firebase idToken中缺乏Givenname以及Familyname申明的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。