how to specify the redirect url for the google sign-in button

后端 未结 4 894
悲&欢浪女
悲&欢浪女 2021-01-12 10:44

i was wondering how to specify the redirect url for a google sign-in button, here is the button:

 
相关标签:
4条回答
  • 2021-01-12 11:15

    As of June 2020, can you do it like this. Documentation : https://developers.google.com/identity/sign-in/web/reference

    function renderButton() {
          gapi.signin2.render('my-signin2', {
            'scope': 'profile email',
            'width': 240,
            'height': 50,
            'longtitle': true,
            'theme': 'dark',
            'ux_mode': 'redirect',
            'redirect_uri': 'REDIRECT URL HERE',
            'onsuccess': onSuccess,
            'onfailure': onFailure
          });
        }
    
    0 讨论(0)
  • 2021-01-12 11:22

    I believe Google changed this a while ago.

    What I used to redirect:

    gapi.load('auth2', () => {
      auth2 = gapi.auth2.init({
        client_id: '615643915869-vufkml5ogm4j4a01qbshk9darkhq7vpr.apps.googleusercontent.com',
        fetch_basic_profile: true,
        ux_mode: redirect,
        redirect_uri: ''
      });
    
      auth2.signIn().then(() => {
        var profile = auth2.currentUser.get().getBasicProfile();
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('ID: ' + profile.getId());
        console.log('Full Name: ' + profile.getName());
        console.log('Given Name: ' + profile.getGivenName());
        console.log('Family Name: ' + profile.getFamilyName());
        console.log('Email: ' + profile.getEmail());
    
      }).catch((error) => {
        console.error('Google Sign Up or Login Error: ', error)
      });
    });
    

    The parameter ux_mode can be either 'popup' or 'redirect'.
    If the latter is chosen the parameter redirect_uri can take your url

    If using ux_mode='redirect', this parameter allows you to override the default redirect_uri that will be used at the end of the consent flow. The default redirect_uri is the current URL stripped of query parameters and hash fragment.

    Here is Link to the Documentation

    0 讨论(0)
  • 2021-01-12 11:29

    Param name is data-redirecturi. Example:

    <div class="g-signin2" 
       data-onsuccess="onSignIn"
       data-scope="https://www.googleapis.com/auth/plus.login"
       data-accesstype="offline"
       data-redirecturi="https://www.example.com/redirect_uri"></div>
    

    Note that you don't have to set data-cookiepolicy, it's single_host_origin by default.

    0 讨论(0)
  • 2021-01-12 11:31

    with this you can make that with the sign-in button of google

    first call to the api sdk google script

    <script src="https://apis.google.com/js/platform.js" async defer></script>
    

    then set the meta tag of you client id

    <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
    

    and in the script of the button, set something like this:

    <div class="g-signin2" data-onsuccess="onSignIn" onclick="location.href='page url'"></div>
    
    0 讨论(0)
提交回复
热议问题