Manually trigger opening of Google sign-in popup with "Google Identity Services" to get `id_token`

Viewed 33

Is there a programmable way to get the id_token with "Google Identity Services" like you could previously with gapi.auth2.authorize? I have a use case where I have a completelly custom google sign-in button and by clicking it, I'm calling gapi.auth2.authorize to show the Google sign-in popup window. After user successfull sign in, I receive the id_token. This token is then send to backend server to validate/authenticate the user and to sign him in to my application. For example:

    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
    })

As far I can see there is now way how to do it with the new "Google Identity Services" API. As I understand, you use methods under google.accounts.id for authentication and under google.accounts.oauth2 for authorization. With methods under google.accounts.id I can just show the prompt (One Tap popup) or call renderButton (the rendered button can be customized just to some extent). And methods under google.accounts.oauth2 return just "access_token" (e.g. requestAccessToken) or "authorization code" (e.g. requestCode).

I would have assumed there would be some method like requestIdToken (or requestCredential) under google.accounts.id.

0 Answers
Related