Skip to content

Commit 59e86b2

Browse files
committed
Update documentation based on auth2 deprecation
Remove auth2 references and replace with links to deprecation notice Remove cors information Update/remove samples
1 parent 63ed219 commit 59e86b2

File tree

9 files changed

+5
-369
lines changed

9 files changed

+5
-369
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ developers. It offers simple, flexible access to many Google APIs.
1111

1212
The JavaScript client library [supports these Google APIs](https://developers.google.com/apis-explorer/#p/).
1313

14-
The library supports [OAuth 2 authentication](docs/auth.md).
15-
1614
If you use TypeScript, you can install [`@types/gapi`](https://www.npmjs.com/package/@types/gapi) for autocompletion.
1715

1816
# Documentation
@@ -24,7 +22,6 @@ If you use TypeScript, you can install [`@types/gapi`](https://www.npmjs.com/pac
2422

2523
- [Auth](docs/auth.md)
2624
- [Batch](docs/batch.md)
27-
- [CORS](docs/cors.md)
2825
- [Discovery Documents](docs/discovery.md)
2926
- [FAQ](docs/faq.md)
3027
- [Promises](docs/promises.md)

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ access to many Google APIs.
99
- [Getting Started](start.md)
1010
- [Auth](auth.md)
1111
- [Batch](batch.md)
12-
- [CORS](cors.md)
1312
- [Discovery Documents](discovery.md)
1413
- [FAQ](faq.md)
1514
- [Promises](promises.md)

docs/auth.md

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,3 @@
11
# Authentication
22

3-
[](#top_of_page)Overview
4-
------------------------
5-
6-
To access a user's private data, your application must work with Google's policies for authentication and authorization.
7-
8-
Google defines two levels of API access:
9-
10-
<table>
11-
<tr>
12-
13-
Level
14-
15-
16-
Description
17-
18-
19-
Requires:
20-
21-
tr>
22-
<tr>
23-
24-
Simple
25-
26-
27-
API calls do not access any private user data
28-
29-
30-
API key
31-
32-
tr>
33-
<tr>
34-
35-
Authorized
36-
37-
38-
API calls can read and write private user data, or the
39-
application's own data
40-
41-
42-
API key plus OAuth 2.0 credentials (different for
43-
different application types)
44-
45-
tr>
46-
table>
47-
48-
[](#top_of_page)Getting access keys for your application
49-
--------------------------------------------------------
50-
51-
To get access keys, go to the [Google Developers Console](https://console.developers.google.com) and specify your application's name and the Google APIs it will access. For simple access, Google generates an API key that uniquely identifies your application in its transactions with the Google Auth server.
52-
53-
For authorized access, you must also tell Google your website's protocol and domain. In return, Google generates a client ID. Your application submits this to the Google Auth server to get an OAuth 2.0 access token.
54-
55-
For detailed instructions for this process, see the [Getting started](start.md) page.
56-
57-
See below for details and examples of how to use these credentials in your application.
58-
59-
[](#top_of_page)Simple access using the API key
60-
-----------------------------------------------
61-
62-
The API key identifies your application for requests that don't require authorization.
63-
64-
Whether or not your application requires authorized access, your code should call `gapi.client.init` with the `apiKey` parameter.
65-
66-
```js
67-
gapi.client.init({ 'apiKey': 'YOUR_API_KEY', ...
68-
}).then(...)
69-
```
70-
71-
For a complete example of simple API access, follow [this link](samples.md#LoadinganAPIandMakingaRequest).
72-
73-
[](#top_of_page)Authorized access
74-
---------------------------------
75-
76-
To access a user's personal information, your application must work with Google's OAuth 2.0 mechanism.
77-
78-
### OAuth 2.0 basics
79-
80-
You may want to start with this overview of [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/accounts/docs/OAuth2).
81-
82-
Behind the scenes, the OAuth 2.0 mechanism performs a complex operation to authenticate the user, the application, and the Google Auth server. The components of the JavaScript client library manage this process for you, so that all your code has to do is pass in the following objects:
83-
84-
* The client ID you received when you registered your application
85-
* The scope object that specifies which data your application will use
86-
87-
### About scope
88-
89-
The scope object defines the level of access to a particular API that your application will use. For more information about how scopes work, refer to [this OAuth 2.0 documentation](https://developers.google.com/accounts/docs/OAuth2.html). The scope is a **space delimited string**. The following example represents read-only access to a user's Google Drive:
90-
91-
https://www.googleapis.com/auth/drive.readonly
92-
93-
### OAuth 2.0 authorization flow
94-
95-
The JavaScript client library uses the [OAuth 2.0 client-side flow](https://developers.google.com/accounts/docs/OAuth2UserAgent) for making requests that require authorization. If you would like to see what this looks like in action, check out [Google's OAuth 2.0 Playground](https://developers.google.com/oauthplayground/).
96-
97-
OAuth 2.0 authorization in the JavaScript client library proceeds as follows:
98-
99-
1. The user clicks a "login" link.
100-
2. The browser shows a popup that allows the user to authenticate and authorize the web application.
101-
3. After successful authorization, the browser redirects the user back to the calling application (your application).
102-
4. The callback saves the authorization token and closes the popup.
103-
104-
After this, the user is signed in to your application, and the application is authorized to access the user's personal data. The user's sign-in state is persistent across sessions, so the next time the user opens your application, the user is automatically signed in.
105-
106-
[](#top_of_page)Auth example
107-
----------------------------
108-
109-
See the [auth example](samples.md#authorizing-and-making-authorized-requests) on the Samples page.
110-
111-
[](#top_of_page)Making a request with CORS
112-
------------------------------------------
113-
114-
To make an authenticated [CORS](http://www.w3.org/TR/cors/) request, you can add the OAuth 2.0 access token to the request header or add it as a URL parameter. For details, read the [CORS documentation](cors.md).
115-
116-
[](#top_of_page)The standalone auth client
117-
------------------------------------------
118-
119-
Your application can also use a subset of the full JavaScript client library that performs authentication and nothing else. It includes only the `gapi.auth` methods.
120-
121-
Use the standalone auth client in web applications that will run in environments with full CORS support, such as Chrome extensions and mobile browsers. If your application may run on browsers which do not support CORS, or if you want to use other features of the JavaScript library, use the standard JavaScript client.
122-
123-
For information about how to load and use the auth client, see the [CORS documentation](cors.md).
3+
gapi.auth2 has been deprecated and replaced with Google Identity Services. Please see https://developers.googleblog.com/2021/08/gsi-jsweb-deprecation.html for more information. If you have questions related to authentication/authorization please look at the associated documentation or post questions on Stack Overflow with the google-oauth tag.

docs/cors.md

Lines changed: 0 additions & 95 deletions
This file was deleted.

docs/faq.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,6 @@
44

55
The JavaScript client library does not support local pages and the `file://` protocol. The application must be hosted on a server (can be localhost).
66

7-
### Does the JavaScript client library set authentication cookies?
8-
9-
The JavaScript client library does not write any auth cookies. `gapi.auth.getToken` and `gapi.auth.setToken` provide access to the auth token.
10-
11-
### How do I refresh the auth token, and how often should I do it?
12-
13-
Refresh the token by calling `gapi.auth.authorize` with the client ID, the scope and `immediate:true` as parameters.
14-
15-
Currently, the auth token expires after one hour. A common practice is to refresh the auth token after 45 minutes. If you refresh the auth token too often (every five minutes, for example) you will run into the refresh rate limit. (The rate limit is per-user, so the number of user connections is not an issue.)
16-
17-
The auth token's `expires_in` field will tell you the token's time to expiration.
18-
19-
The [authSample.html file](https://github.com/google/google-api-javascript-client/blob/master/samples/authSample.html) contains one example of code that handles signin and signout but not token refreshes.
20-
21-
### Is it possible to use the JavaScript client library in an installed application?
22-
23-
At this time, the JavaScript client library supports web applications only. For mobile devices you can use one of our other client libraries like the one for [Objective-C](http://code.google.com/p/google-api-objectivec-client/)
24-
25-
### How can I use the JavaScript client library to log the user out of my application?
26-
27-
The JavaScript client library does not directly support logging the user out of the application. Typically, developers include a logout link to https://accounts.google.com/logout.
28-
29-
Since logging out of the application also logs the user out of the Google account, it is not recommended to log the user out unless the user requests this explicitly.
30-
31-
For a workaround that allows your application to log the user out programatically, see [this topic](https://groups.google.com/forum/?fromgroups=#!topic/google-api-javascript-client/PCs8xXV4wxk) in the JavaScript client library discussion group.
32-
33-
347
### Is it possible to use the JavaScript client library in a Chrome Extension?
358

369
Chrome Extensions using Manifest v3 do not allow [remotely hosted code](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/#remotely-hosted-code), so the Javascript client library cannot be used in this case.

docs/reference.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
3939
4040
A colon (:) separated list of gapi libraries. Ex:
41-
"client:auth2".
41+
"client:iframes".
4242
4343
4444
@@ -148,12 +148,6 @@ alert('gapi.client could not load in a timely manner!');
148148
<p>
149149
Initializes the JavaScript client with API key, OAuth client ID, scope, and
150150
151-
If OAuth client ID and scope are provided, this function will load the
152-
gapi.auth2 module to perform OAuth. The gapi.client.init function
153-
can be run multiple times, such as to set up more APIs, to change API key, or initialize
154-
OAuth lazily. Note that the scope and clientId parameters cannot
155-
be provided multiple times, since the gapi.auth2 module can only be initialized
156-
once.
157151
p>
158152
<p>
159153
Arguments:
@@ -458,9 +452,7 @@ alert('gapi.client could not load in a timely manner!');
458452
gapi.client.setToken(tokenObject)
459453
h3>
460454
<p>
461-
Sets the authentication token to use in requests. This should be used if the token was
462-
obtained without using the gapi.auth2 authentication library (for instance,
463-
when using Firebase to authenticate users).
455+
Sets the authentication token to use in requests.
464456
p>
465457
<p>
466458
Arguments:

docs/samples.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Samples
22

3-
This page provides three detailed examples which demonstrate the library's functionality. Browse the [project source](https://github.com/google/google-api-javascript-client/tree/master/samples) for additional samples.
3+
This page provides three detailed examples which demonstrate the library's functionality. Additional samples(including authenticated/authorized requests) can be found in API specific documentation such as the [Google Drive API Quick Start](https://developers.google.com/drive/api/quickstart/js).
44

55
Loading an API and Making a Request
66
-----------------------------------
@@ -41,51 +41,3 @@ This snippet shows how to load an API and make a request. In this case, the requ
4141
body>
4242
html>
4343
```
44-
45-
## Authorizing and Making Authorized Requests
46-
47-
The following sample demonstrates how to get "authorized" access to a Google API using OAuth 2.0. See the full sample at [authSample.html](https://github.com/google/google-api-javascript-client/blob/master/samples/authSample.html).
48-
49-
It's called "authorized" access because the user must give the application direct authorization to use personal data. Simple web-based applications using JavaScript usually get this authorization the way this example does: by displaying button for the user to click. This action triggers a call to a Google auth server, which pops up a standard authorization dialog. For details, see the [Authentication page](auth.md).
50-
51-
**Note:** The full sample uses `gapi.load('client:auth2', ...)` to load both the `client` module (for dealing with API requests) and the `auth2` module (for dealing with OAuth 2.0) upfront. The `gapi.client.init` fuction lazily loads `auth2` if it is needed. If you are sure your app needs auth, loading the two modules `'client:auth2'` together before you call `gapi.client.init` will save one script load request.
52-
53-
To make `gapi.client.init` set up OAuth correctly, you would have to assign the `clientID` variable the client ID generated when you registered your application (for instructions see [Integrating Google Sign-In into your web app](https://developers.google.com/identity/sign-in/web/sign-in)). The other parameter is `scope`, which in this case is just the scope for user profile permission.
54-
55-
When the user clicks **Authorize**, the `gapi.auth2.getAuthInstance().signIn()` function is called, which shows user a popup window to let user authorize. Note that the `gapi.auth2.getAuthInstance().signIn()` can be only called from a user interaction context for most browsers (i.e. do not call it when your app starts, but call it in a button click handler).
56-
57-
**Note:** When you authorize your application using Oauth 2.0, you do not also need to set the API key as in the first example. However, it is a good practice to do so, in case your code ever expands to handle unauthorized requests.
58-
59-
## Loading the Library Asychronously
60-
61-
The following code snippet shows how to load the library without blocking UI loading. (The `onreadystatechange` is used to support old versions of IE.)
62-
63-
```html
64-
<html>
65-
<head>
66-
<script>
67-
function start() {
68-
gapi.client.init({
69-
'apiKey': '...',
70-
'discoveryDocs': [...],
71-
...
72-
}).then(...)
73-
};
74-
75-
function loadClient() {
76-
gapi.load('client', start);
77-
}
78-
script>
79-
<script async defer src="https://apis.google.com/js/api.js"
80-
onload="this.onload=function(){};loadClient()"
81-
onreadystatechange="if (this.readyState === 'complete') this.onload()">script>
82-
head>
83-
<body>
84-
<div id="body-to-be-shown-before-gapi-load">div>
85-
body>
86-
html>
87-
```
88-
89-
## Putting it all together
90-
91-
The file [authSample.html](https://github.com/google/google-api-javascript-client/blob/master/samples/authSample.html) expands on the concepts on this page and provides a more complete example of making an authenticated call to the Google People API.

0 commit comments

Comments
 (0)