Skip to main content

API Updates for Sign-In with Google

With the release of Google Play services 8.3, we’ve made a lot of improvements to Sign-In with Google. In the first blog postof this ongoing series, we discussed the user interface improvements. Today, we will look further into the changes to the API to make building apps that Sign-In with Google easier than ever before.

Changes to basic sign in flow

When building apps that sign in with Google, you’ll notice that there are a lot of changes to make your code easier to understand and maintain.
Prior to this release, if you built an app that used Sign-In with Google, you would build one that attempted to connect to a GoogleApiClient. At this point the user was presented with an account picker and/or a permissions dialog, both of which would trigger a connection failure. You would have to handle these connection failures in order to sign in. Once the GoogleApiClient connected, then the user was considered to be signed in and the permissions could be granted. The process is documented in a CodeLab here.
Now, your code can be greatly simplified.
The process of signing in and connecting the GoogleApiClient are handled separately. Signing in is achieved with aGoogleSignInOptions object, on which you specify the parameters of the sign in, such as scopes that you desire. Here’s a code example:
 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)  
     .requestEmail()  
     .build();  
Once you have a GoogleSignInOptions object, you can use it to configure the GoogleApiClient:
Here’s where your code will diverge greatly in the new API. Now, if you want to connect with a Google Account, instead of handling errors on the GoogleApiClient, you’ll instead use an intent that is initialized using the client.
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
Starting the intent will give you the account picker, and the scopes permission dialog if your GoogleSignInOptions requested anything other than basic scope. Once the user has finished interacting with the dialogs, an OnActivityResult callback will fire, and it will contain the requisite sign-in information.
 @Override  
 public void onActivityResult(int requestCode, int resultCode, Intent data) {  
   super.onActivityResult(requestCode, resultCode, data);  
   // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);  
   if (requestCode == RC_SIGN_IN) {  
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);  
     handleSignInResult(result);  
   }  
 }  
You can learn more about this code in the Integrating Google Sign-In quickstart, or by looking at the sample code.

Silent Sign-In

To further reduce friction for users in a multi-device world, the API supports silent sign in. In this case, if your user has given authorization to the app on a different device, the details will follow their account, and they don’t need to re-give them on future devices that they sign into, unless they deauthorize. An existing sign-in is also cached and available synchronously on the current device is available.
Using it is as simple as calling the silentSignIn method on the API.
OptionalPendingResult opr = 
      Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
Then, you can check the isDone() method on the pending result -- and if it returns true, the user is signed in, and you can get their status from the PendingResult. If it isn’t then you have to wait for a callback with the SignInResult
 if (pendingResult.isDone()) {  
    doStuffWith(pendingResult.get());  
  } else {  
    // There's no immediate result ready, displays some progress indicator and waits for the  
    // async callback.  
    showProgressIndicator();  
    pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {  
      @Override  
      public void onResult(@NonNull GoogleSignInResult result) {  
        updateButtonsAndStatusFromSignInResult(result);  
        hideProgressIndicator();  
      }  
    });  
  }  

Customizing the Sign-In Button

When building apps that Sign-In with Google, we provide a SignInButton object that has the Google branding, and which looks like this:

You can customize this button with a number of properties and constants that are documented in the API here.
The branding guidelines are available here, and they include versions of the buttons in PNG, SVG, EPS and other formats in many resolutions, including all the different states of the button. These files may be used for localization of the button, and if you need to match the style of the button to your app, guidelines are provided.
This only deals with the Android side of your app. You’ll likely have a server back end, and you may want to use the credentials on that securely.
In the next blog post, we’ll discuss how to use Sign-In with Google in server-side scenarios, including how to securely pass your credentials to your own server, and how to use Google back-end services, such as Google Drive, with the permission and credentials from users.

Comments

Popular posts from this blog

MICROSOFT LYNC 2013

ARTICLES MICROSOFT LYNC 2013 Microsoft Lync and Skype will be connected by June What's new in Office 2016 for Windows Microsoft's Lync has become the standard for corporate web conferencing and  chat . In the latest version for 2013, Lync gets even better.  Features Lync has more features than you can shake a stick at.  Microsoft has had years of experience creating a well-rounded chat client.  Lync includes not only instant messaging but video conferencing and powerful collaboration tools. Instant messaging works just as you'd expect. The current status of your contacts is displayed clearly next to their names. These statuses are integrated into  Outlook  as well so you know when someone is available to chat with. Coferencing is one of the useful feathures of Lync. You can share audio, video, screens, as well as white boards and polls. New for this version of Lync is HD video. Microsoft is using H.264 SVC to make sure...

Windows 8 / 8.1 Product key for activation 2015

Windows is doubtlessly one of the best operating system out there. It has many awesome features and updates which makes it unique and keeps the users attached to itself. Not only easy usable interface also some features which is very unique compared to other  open  source and Linux operating systems. Thus it is suitable for users such as  windows 8 . 1 key ,  windows 8  keys,  product key  for  windows 8 ,  windows 8   product key , windows 8 .1 CD key, window 8.1  product key . Windows Product Keys 8 There are many versions in the windows 8. It has trail preview versions such as windows 8 developer preview, windows 8 release preview, & finally the windows 8 RTM which is the retail pack of the windows. Not only the PC operating system but also the server OS which is required to run powerful servers also available  with the windows release. Windows 8.1 and 8 Product Key List :...

[Latest] 100% Working Windows 7 Ultimate Serial Key

This post gives you the most wanted serial keys or the product keys of the  Windows ultimate version . This is new post where we give you the latest and working serial keys. Sample Keys : 14KIU-PKL69-OI8CV-Q2H7C-AYVAK Windows 7 ultimate  serial keys KIJ71-0MNJK-Z63TY-KULDE-EEPSI Read below for more keys: Microsoft is one of the leading OS developer and has released a lot of the windows versions in the previous years. It has  windows 7 ultimate  product key  64 bit free  and  free windows 7 ultimate product key . The  latest version  of the Windows is Windows 8.1 but nowadays the the most used version in the windows OS is mainly windows 7 . People loves the very simple to use interface and many other features. After the windows XP people mostly love the windows 7 version. Windows 7 has many divisions such as  windows 7 ultimate,windows 7 home premium, windows 7 professional ,...