javascript - Google+ vs Google Identity Platform API -


tl;dr: can explain difference in implementing client-side google login flow between these 2 platforms?

the backstory:

i've been trying implement client-side google sign in website. first, implemented google+ platform global settings using tags, user session monitored. got info here: https://developers.google.com/+/web/signin/

however, encountered problem site automatically check user login state if user not logged in, resulted in many 'toastr' messages of 'logged out', implemented in signincallback function. pretty annoyting.

so did research , stumbled across 'quick start app' , browsed through it. way more complicated guide, many elements documented on google identity platform, here: https://developers.google.com/identity/sign-in/web/reference

now don't understand correct way of implementing login - lightweight google+ button tag callback check user state, or robust gip way listeners, gapi instances , all? different these platforms offer?

both google+ platform sign-in (gapi.auth) , identity platform (gapi.auth2) related , work similarly.

the chief differences between 2 are:

gapi.auth2 supports more modern javascript (listeners , promises) can this:

var signinchanged = function (val) {   console.log('signin state changed ', val);   document.getelementbyid('signed-in-cell').innertext = val; };  auth2.issignedin.listen(signinchanged); 

...auth2 has more explicit syntax give more control on behavior:

gapi.load('auth2', function() {   auth2 = gapi.auth2.init({     client_id: 'client_id.apps.googleusercontent.com',     fetch_basic_profile: true,     scope: 'profile'   });    // sign user in, , retrieve id.   auth2.signin().then(function() {     console.log(auth2.currentuser.get().getid());   }); }); 

and auth2 provides basic profile support without needing 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, recommend using approaches documented @ https://developers.google.com/identity/sign-in/, such https://developers.google.com/identity/sign-in/web/.

implementing login correctly depend on kind of sign-in want:

  • client-only, can use javascript/ios/android clients
  • hybrid client-server auth, need implement similar 1 of quickstarts

if doing client-only, should pretty simple: authorize user , access resources using api client. if doing more sophisticated, e.g. managing sessions , forth, should use id tokens api client authorize user's session after authorizing server using authorization code.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -