是否有一种可编程的方式可以id_token像以前一样使用“Google Identity Services” gapi.auth2.authorize?我有一个用例,我有一个完全自定义的谷歌登录按钮,通过单击它,我调用gapi.auth2.authorize以显示谷歌登录弹出窗口。用户成功登录后,我收到id_token. 然后,该令牌被发送到后端服务器以验证/验证用户身份并让他登录到我的应用程序。例如:
const config: gapi.auth2.AuthorizeConfig = {
client_id: <client_id>,
scope: 'email profile openid',
prompt: 'consent',
response_type: 'id_token',
include_granted_scopes: false
};
gapi.auth2.authorize(config, (response) => {
console.log(response.id_token);
// redirect or send to backend server
})
Run Code Online (Sandbox Code Playgroud)
据我所知,现在有办法使用新的“Google Identity Services”API 来做到这一点。据我了解,您使用以下方法google.accounts.id进行身份验证和google.accounts.oauth2授权。使用下面的方法,google.accounts.id我可以只显示prompt(一击弹出窗口)或调用renderButton(渲染的按钮可以在某种程度上进行自定义)。并且下面的方法google.accounts.oauth2仅返回“access_token”(例如requestAccessToken)或“授权代码”(例如requestCode)。
我本以为会有一些类似requestIdToken(或requestCredential)的方法google.accounts.id。
google-oauth ×1