javascript - Google+ vs Google Identity Platform API - Stack Overflow

tl;dr: can someone explain what exactly is the difference in implementing client-side Google login flow

tl;dr: can someone explain what exactly is the difference in implementing client-side Google login flow between these two platforms?

The backstory:

I've been trying to implement client-side Google sign in to my website. First, I implemented the Google+ platform with global settings using tags, so user session is monitored. Got the info here: /+/web/signin/

However, I encountered a problem where the site would automatically check for user login state if the user is not logged in, which resulted in many 'toastr' messages of 'Logged out', which I implemented in the signInCallback function. It was pretty annoyting.

So I did some research and stumbled across their 'quick start app' and browsed through it. It is WAY more plicated than their guide, many elements were documented on Google Identity Platform, here:

Now I don't really understand what is the correct way of implementing their login - is it the lightweight Google+ button with tag callback check for user state, or is it the robust GIP way with listeners, gapi instances and all? What exactly different do these platforms offer?

tl;dr: can someone explain what exactly is the difference in implementing client-side Google login flow between these two platforms?

The backstory:

I've been trying to implement client-side Google sign in to my website. First, I implemented the Google+ platform with global settings using tags, so user session is monitored. Got the info here: https://developers.google./+/web/signin/

However, I encountered a problem where the site would automatically check for user login state if the user is not logged in, which resulted in many 'toastr' messages of 'Logged out', which I implemented in the signInCallback function. It was pretty annoyting.

So I did some research and stumbled across their 'quick start app' and browsed through it. It is WAY more plicated than their guide, many elements were documented on Google Identity Platform, here: https://developers.google./identity/sign-in/web/reference

Now I don't really understand what is the correct way of implementing their login - is it the lightweight Google+ button with tag callback check for user state, or is it the robust GIP way with listeners, gapi instances and all? What exactly different do these platforms offer?

Share Improve this question edited Jun 12, 2015 at 18:29 class 8,68130 silver badges30 bronze badges asked Apr 22, 2015 at 13:41 IdefixxIdefixx 4726 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

Both the Google+ platform sign-in (gapi.auth) and the Identity platform (gapi.auth2) are related and work similarly.

The chief differences between the two are:

gapi.auth2 supports more modern JavaScript (listeners and promises) so you can do this:

var signinChanged = function (val) {
  console.log('Signin state changed to ', val);
  document.getElementById('signed-in-cell').innerText = val;
};

auth2.isSignedIn.listen(signinChanged);

...auth2 has a more explicit syntax to give you more control over behavior:

gapi.load('auth2', function() {
  auth2 = gapi.auth2.init({
    client_id: 'CLIENT_ID.apps.googleusercontent.',
    fetch_basic_profile: true,
    scope: 'profile'
  });

  // Sign the user in, and then retrieve their ID.
  auth2.signIn().then(function() {
    console.log(auth2.currentUser.get().getId());
  });
});

And auth2 provides basic profile support without needing an extra API call:

if (auth2.isSignedIn.get()) {
  var profile = auth2.currentUser.get().getBasicProfile();
  console.log('ID: ' + profile.getId());
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail());
}

In short, I remend using the approaches documented at https://developers.google./identity/sign-in/, such as https://developers.google./identity/sign-in/web/.

Implementing login correctly will depend on what kind of sign-in you want:

  • Client-only, you can just use the JavaScript/iOS/Android clients
  • Hybrid client-server auth, you will need to implement something similar to one of the quickstarts

If you are doing client-only, then it should be pretty simple: you authorize the user and then access the resources using the API client. If you are doing something more sophisticated, e.g. managing sessions and so forth, you should use ID tokens from the API client to authorize the user's session after authorizing your server using an authorization code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743939082a4533189.html

相关推荐

  • javascript - Google+ vs Google Identity Platform API - Stack Overflow

    tl;dr: can someone explain what exactly is the difference in implementing client-side Google login flow

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信