Dalvinder Singh
Dalvinder Singh

Reputation: 1083

what is scope in GoogleAuthUtil.getToken() method?

I am using OAuth2 for auto login. But I do not know what is scope parameter in getToken() method, Please help me.

Upvotes: 2

Views: 2286

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

OAuth2 authorization uses access token to access APIs instead of using username and password. In normal OAuth2 method we would initially request Authorization code from the Authority using scope, redirect URL, and client id,then exchange the code with client id and client secret to get access token and refresh token. But using Android AccountManager we can obtain the access token easily for Google APIs.

GoogleAuthUtil.getToken() takes three arguments: a Context, an email address, and another string argument called scope. Every information resource that is willing to talk OAuth 2.0 needs to publish which scope (or scopes) it uses. For example, to access the Google+ API, the scope is oauth2:https://www.googleapis.com/auth/plus.me. You can provide multiple space-separated scopes in one call and get a token that provides access to all of them. Code like this might be typical:

private final static String G_PLUS_SCOPE = 
      "oauth2:https://www.googleapis.com/auth/plus.me";
  private final static String USERINFO_SCOPE =   
      "https://www.googleapis.com/auth/userinfo.profile";
  private final static String SCOPES = G_PLUS_SCOPE + " " + USERINFO_SCOPE;

getToken() would be synchronous, but three things keep it from being that simple:

The first time an app asks for a token to access some resource, the system will need to interact with the user to make sure they’re OK with that.

Any time you ask for a token, the system may well have a network conversation with the identity back-end services.

The infrastructure that handles these requests may be heavily loaded and not able to get you your token right away. Rather than keeping you waiting, or just failing, it may ask you to go away and come back a little later.

Courtesy Goes To OAuth Identity Tools

https://developers.google.com/android/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context)

Upvotes: 5

Related Questions