Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
Google Identity Custom Login with JavaScript

With Google Sign-In, we are using a custom button skin (following the branding guidelines mentioned on https://developers.google.com/identity/sign-in/web/build-button) and then calling to sign in manually from JS using essentially this:

gapi.load('auth2', function(){
    gapi.auth2.init().signIn().then(function(response) {
        // handle success
    }).catch(function(error) {
        // handle error/cancel
    });
});

I'm looking at the documentation for Google Identity and it appears neither of those (custom button or trigger sign-in via JS) is possible? Is there a way to do it, that I'm missing? We'd really like to be able to keep the Google sign-in button consistent with our other login buttons and handle UI-friendly resizing, etc. Thanks so much!

Note: I know that google.accounts.id.prompt() is in the documentation, but this doesn't appear to work universally. When I try it, I just get an opt_out_or_no_session error and nothing happens. Plus we'd like to use the Google button, rather than one tap, which is what I think this is for.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The new button supports a set of visual data attributes to choose from. This removes the need for you to host images and maintain branding guidelines. It helps users by ensuring that sign-in using Google looks and feels the same across sites -- consistency is good for everyone.

There is a code generator that can be used to rapidly cycle through all the different size, shape, color, and text options for the sign-in button.

If you can't find attributes which meet your needs it would be great to hear more about what is lacking. If that still doesn't work you can continue with branding guidelines and directly call OpenID Connect endpoints to authenticate users.

If you only want to display the Sign In With Google button, set data-auto_prompt="true" to suppress One Tap. This isn't recommended as it increases the number of steps and friction on sign-in; One Tap improves sign-in rates.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can do that by doing something like this:

const clientLoad = new Promise(resolve => {
  gapi.load('auth2', () => {
    resolve(gapi.auth2.init({ client_id: '<your_client_id>' }));
  });
});

async function login() {
  const client = await clientLoad;
  const response = client.signIn().catch((e) => {
    // in case user closes the popup
    if (e.error === 'popup_closed_by_user') {
      return null;
    }
    throw e;
  });

  // handle your authentication flow with the token received
  console.log(response.getAuthResponse());
}

And in your button:

<button class="your-custom-style" onclick="login()">
  Login with google
</button>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda