GoogleAuthUtil.getToken() 方法的作用域是什么?

what is scope in GoogleAuthUtil.getToken() method?

我正在使用 OAuth2 进行自动登录。但我不知道 getToken() 方法中的范围参数是什么,请帮助我。

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() 采用三个参数:上下文、电子邮件地址和另一个名为范围的字符串参数。每个愿意谈论 OAuth 2.0 的信息资源都需要发布它使用的范围。例如,要访问 Google+ API,作用域是 oauth2:https://www.googleapis.com/auth/plus.me. 您可以在一次调用中提供多个 space 分隔的作用域,并获得一个提供对所有访问的令牌他们中的。像这样的代码可能很典型:

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() 会是同步的,但有三件事让它变得不那么简单:

应用第一次请求令牌访问某些资源时,系统需要与用户交互以确保他们同意。

任何时候您请求令牌,系统都可能与身份后端服务进行网络对话。

处理这些请求的基础架构可能负载很重,无法立即为您获取令牌。与其让你等待,或者只是失败,不如让你离开,稍后再回来。

礼遇 OAuth Identity Tools

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