我已经成功地使用谷歌登录库创建了一个谷歌登录按钮,请求额外的范围,但是我无法弄清楚如何将其转换为 API 请求。我正在使用googleUser.getAuthResponse().id_token
并获取令牌,但我不确定如何将其转换为访问令牌以与我的 API 请求一起发送?
我使用的几乎就是文档中的内容:
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
document.getElementById("acc").src = profile.getImageUrl();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
var oAuthToken = googleUser.getAuthResponse().id_token
}