Skip to content

Commit 70c2b06

Browse files
committed
docs: Added additional documentation for specifying OAuth scopes.
bug: 12650251 Change-Id: I8905ed63208aff82d0c0caf1b3503831f121b09e
1 parent 8319455 commit 70c2b06

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

docs/html/_redirects.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ redirects:
5959
- from: /guide/google/gcm/server-javadoc/...
6060
to: /reference/com/google/android/gcm/server/package-summary.html
6161

62+
- from: /google/play-services/auth.html
63+
to: /google/auth/http-auth.html
64+
6265
- from: /guide/google/play/services.html
6366
to: /google/play-services/index.html
6467

docs/html/google/auth/http-auth.jd

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ public class GetUsernameTask extends AsyncTask<Void, Void, Void>{
342342
"{@docRoot}reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context,%20java.lang.String,%20java.lang.String)">
343343
{@code GoogleAuthUtil.getToken()}</a>, you must provide the app {@link android.content.Context},
344344
the account name retrieved from the account picker, and the scope for your auth
345-
token request. The above sample code (and the attached sample) defines these arguments with
346-
class members that the host activity passes to
347-
the {@link android.os.AsyncTask} class constructor.</p>
345+
token request. The above sample code (and the attached sample) defines these
346+
arguments with class members that the host activity passes to the {@link android.os.AsyncTask} class constructor. For more information about setting the scope, see
347+
the <a href="#SpecifyingScopes">Specifying Scopes</a> section below. </p>
348348

349349
<p class="note"><strong>Note:</strong>
350350
As shown by the {@code fetchToken()} method above, you must handle
@@ -397,8 +397,32 @@ the {@code isDeviceOnline()} method above), see the attached sample app or the
397397
"{@docRoot}reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context,%20java.lang.String,%20java.lang.String)">
398398
{@code GoogleAuthUtil.getToken()}</a>.</p>
399399

400-
401-
400+
<h3 id="SpecifyingScopes">Specifying scopes</h3>
401+
<p>The scope string is used to specify which Google services can be accessed by
402+
an app using the requested auth token. An auth token can be associated with
403+
multiple scopes.</p>
404+
<p>When specifying the scopes in your auth token request, prefix the
405+
scope string with {@code "oauth2:"} followed by a list of one or more OAuth scope
406+
values. Use a space to separate each scope value in the list. To see a list of
407+
valid OAuth scope values for Google services, browse
408+
the <a href="https://developers.google.com/oauthplayground/"
409+
class="external-link">OAuth 2.0 Playground</a>.</p>
410+
<p class="note"><strong>Tip:</strong> Specify {@code "oauth2:&lt;scope&gt;"}
411+
for a single scope. Specify
412+
{@code "oauth2:&lt;scope1&gt; &lt;scope2&gt; &lt;scopeN&gt;"} for multiple
413+
scopes (using a space to separate each scope).</p>
414+
<p>For example, to access the Google Books API, the scope is
415+
{@code "oauth2:https://www.googleapis.com/auth/books"}. To add an additional
416+
scope, say for Google+ login, your code might look like this:</p>
417+
<pre>
418+
private final static String BOOKS_API_SCOPE
419+
= "https://www.googleapis.com/auth/books";
420+
private fina; static String GPLUS_SCOPE
421+
= "https://www.googleapis.com/auth/plus.login";
422+
private final static String mScopes
423+
= "oauth2:" + BOOKS_API_SCOPE + " " + GPLUS_SCOPE;
424+
String token = GoogleAuthUtil.getToken(mActivity, mEmail, mScopes);
425+
</pre>
402426

403427
<h2 id="HandleExceptions">Handle Exceptions</h2>
404428

0 commit comments

Comments
 (0)