Skip to content

Commit 2be3b2f

Browse files
authored
fix: change setApprovalPrompt to setPrompt (#1796)
1 parent afd3b55 commit 2be3b2f

1 file changed

Lines changed: 45 additions & 45 deletions

File tree

docs/oauth-web.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Any application that uses OAuth 2.0 to access Google APIs must have authorizatio
2222

2323
1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the API Console.
2424
2. Click **Create credentials > OAuth client ID**.
25-
3. Complete the form. Set the application type to `Web application`. Applications that use languages and frameworks like PHP, Java, Python, Ruby, and .NET must specify authorized **redirect URIs**. The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses.
26-
27-
For testing, you can specify URIs that refer to the local machine, such as `http://localhost:8080`. With that in mind, please note that all of the examples in this document use `http://localhost:8080` as the redirect URI.
28-
25+
3. Complete the form. Set the application type to `Web application`. Applications that use languages and frameworks like PHP, Java, Python, Ruby, and .NET must specify authorized **redirect URIs**. The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses.
26+
27+
For testing, you can specify URIs that refer to the local machine, such as `http://localhost:8080`. With that in mind, please note that all of the examples in this document use `http://localhost:8080` as the redirect URI.
28+
2929
We recommend that you design your app's auth endpoints so that your application does not expose authorization codes to other resources on the page.
3030

3131
After creating your credentials, download the **client_secret.json** file from the API Console. Securely store the file in a location that only your application can access.
@@ -56,7 +56,7 @@ To run the PHP code samples in this document, you'll need:
5656
```sh
5757
php composer.phar require google/apiclient:^2.0
5858
```
59-
59+
6060
## Obtaining OAuth 2.0 access tokens
6161

6262
The following steps show how your application interacts with Google's OAuth 2.0 server to obtain a user's consent to perform an API request on the user's behalf. Your application must have that consent before it can execute a Google API request that requires user authorization.
@@ -103,8 +103,8 @@ $client->setAuthConfig('client_secret.json');
103103
104104
##### `redirect_uri`
105105
106-
**Required**. Determines where the API server redirects the user after the user completes the authorization flow. The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in the [API Console](https://console.developers.google.com/). If this value doesn't match an authorized URI, you will get a 'redirect_uri_mismatch' error. Note that the `http` or `https` scheme, case, and trailing slash ('`/`') must all match.
107-
106+
**Required**. Determines where the API server redirects the user after the user completes the authorization flow. The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in the [API Console](https://console.developers.google.com/). If this value doesn't match an authorized URI, you will get a 'redirect_uri_mismatch' error. Note that the `http` or `https` scheme, case, and trailing slash ('`/`') must all match.
107+
108108
To set this value in PHP, call the `setRedirectUri` function. Note that you must specify a valid redirect URI for your API Console project.
109109
110110
```php
@@ -113,24 +113,24 @@ $client->setRedirectUri('http://localhost:8080/oauth2callback.php');
113113

114114
##### `scope`
115115

116-
**Required**. A space-delimited list of scopes that identify the resources that your application could access on the user's behalf. These values inform the consent screen that Google displays to the user.
117-
116+
**Required**. A space-delimited list of scopes that identify the resources that your application could access on the user's behalf. These values inform the consent screen that Google displays to the user.
117+
118118
Scopes enable your application to only request access to the resources that it needs while also enabling users to control the amount of access that they grant to your application. Thus, there is an inverse relationship between the number of scopes requested and the likelihood of obtaining user consent. To set this value in PHP, call the `addScope` function:
119119

120120
```php
121121
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
122122
```
123123

124-
The [OAuth 2.0 API Scopes](https://developers.google.com/identity/protocols/googlescopes) document provides a full list of scopes that you might use to access Google APIs.
125-
124+
The [OAuth 2.0 API Scopes](https://developers.google.com/identity/protocols/googlescopes) document provides a full list of scopes that you might use to access Google APIs.
125+
126126
We recommend that your application request access to authorization scopes in context whenever possible. By requesting access to user data in context, via [incremental authorization](#Incremental-authorization), you help users to more easily understand why your application needs the access it is requesting.
127127

128128
##### `access_type`
129129

130-
**Recommended**. Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are `online`, which is the default value, and `offline`.
131-
132-
Set the value to `offline` if your application needs to refresh access tokens when the user is not present at the browser. This is the method of refreshing access tokens described later in this document. This value instructs the Google authorization server to return a refresh token _and_ an access token the first time that your application exchanges an authorization code for tokens.
133-
130+
**Recommended**. Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are `online`, which is the default value, and `offline`.
131+
132+
Set the value to `offline` if your application needs to refresh access tokens when the user is not present at the browser. This is the method of refreshing access tokens described later in this document. This value instructs the Google authorization server to return a refresh token _and_ an access token the first time that your application exchanges an authorization code for tokens.
133+
134134
To set this value in PHP, call the `setAccessType` function:
135135

136136
```php
@@ -139,10 +139,10 @@ $client->setAccessType('offline');
139139

140140
##### `state`
141141

142-
**Recommended**. Specifies any string value that your application uses to maintain state between your authorization request and the authorization server's response. The server returns the exact value that you send as a `name=value` pair in the hash (`#`) fragment of the `redirect_uri` after the user consents to or denies your application's access request.
143-
144-
You can use this parameter for several purposes, such as directing the user to the correct resource in your application, sending nonces, and mitigating cross-site request forgery. Since your `redirect_uri` can be guessed, using a `state` value can increase your assurance that an incoming connection is the result of an authentication request. If you generate a random string or encode the hash of a cookie or another value that captures the client's state, you can validate the response to additionally ensure that the request and response originated in the same browser, providing protection against attacks such as cross-site request forgery. See the [OpenID Connect](https://developers.google.com/identity/protocols/OpenIDConnect#createxsrftoken) documentation for an example of how to create and confirm a `state` token.
145-
142+
**Recommended**. Specifies any string value that your application uses to maintain state between your authorization request and the authorization server's response. The server returns the exact value that you send as a `name=value` pair in the hash (`#`) fragment of the `redirect_uri` after the user consents to or denies your application's access request.
143+
144+
You can use this parameter for several purposes, such as directing the user to the correct resource in your application, sending nonces, and mitigating cross-site request forgery. Since your `redirect_uri` can be guessed, using a `state` value can increase your assurance that an incoming connection is the result of an authentication request. If you generate a random string or encode the hash of a cookie or another value that captures the client's state, you can validate the response to additionally ensure that the request and response originated in the same browser, providing protection against attacks such as cross-site request forgery. See the [OpenID Connect](https://developers.google.com/identity/protocols/OpenIDConnect#createxsrftoken) documentation for an example of how to create and confirm a `state` token.
145+
146146
To set this value in PHP, call the `setState` function:
147147

148148
```php
@@ -151,8 +151,8 @@ $client->setState($sample_passthrough_value);
151151

152152
##### `include_granted_scopes`
153153

154-
**Optional**. Enables applications to use incremental authorization to request access to additional scopes in context. If you set this parameter's value to `true` and the authorization request is granted, then the new access token will also cover any scopes to which the user previously granted the application access. See the [incremental authorization](#Incremental-authorization) section for examples.
155-
154+
**Optional**. Enables applications to use incremental authorization to request access to additional scopes in context. If you set this parameter's value to `true` and the authorization request is granted, then the new access token will also cover any scopes to which the user previously granted the application access. See the [incremental authorization](#Incremental-authorization) section for examples.
155+
156156
To set this value in PHP, call the `setIncludeGrantedScopes` function:
157157

158158
```php
@@ -161,10 +161,10 @@ $client->setIncludeGrantedScopes(true);
161161

162162
##### `login_hint`
163163

164-
**Optional**. If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server. The server uses the hint to simplify the login flow either by prefilling the email field in the sign-in form or by selecting the appropriate multi-login session.
165-
166-
Set the parameter value to an email address or `sub` identifier, which is equivalent to the user's Google ID.
167-
164+
**Optional**. If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server. The server uses the hint to simplify the login flow either by prefilling the email field in the sign-in form or by selecting the appropriate multi-login session.
165+
166+
Set the parameter value to an email address or `sub` identifier, which is equivalent to the user's Google ID.
167+
168168
To set this value in PHP, call the `setLoginHint` function:
169169

170170
```php
@@ -173,12 +173,12 @@ $client->setLoginHint('timmerman@google.com');
173173

174174
##### `prompt`
175175

176-
**Optional**. A space-delimited, case-sensitive list of prompts to present the user. If you don't specify this parameter, the user will be prompted only the first time your app requests access.
177-
176+
**Optional**. A space-delimited, case-sensitive list of prompts to present the user. If you don't specify this parameter, the user will be prompted only the first time your app requests access.
177+
178178
To set this value in PHP, call the `setApprovalPrompt` function:
179179

180180
```php
181-
$client->setApprovalPrompt('consent');
181+
$client->setPrompt('consent');
182182
```
183183

184184
Possible values are:
@@ -200,16 +200,16 @@ Prompt the user to select an account.
200200
Redirect the user to Google's OAuth 2.0 server to initiate the authentication and authorization process. Typically, this occurs when your application first needs to access the user's data. In the case of [incremental authorization](#incremental-authorization), this step also occurs when your application first needs to access additional resources that it does not yet have permission to access.
201201

202202
1. Generate a URL to request access from Google's OAuth 2.0 server:
203-
203+
204204
```php
205205
$auth_url = $client->createAuthUrl();
206206
```
207-
207+
208208
2. Redirect the user to `$auth_url`:
209-
209+
210210
```php
211211
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
212-
```
212+
```
213213

214214
Google's OAuth 2.0 server authenticates the user and obtains consent from the user for your application to access the requested scopes. The response is sent back to your application using the redirect URL you specified.
215215

@@ -233,7 +233,7 @@ An authorization code response:
233233

234234
https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
235235

236-
> **Important**: If your response endpoint renders an HTML page, any resources on that page will be able to see the authorization code in the URL. Scripts can read the URL directly, and the URL in the `Referer` HTTP header may be sent to any or all resources on the page.
236+
> **Important**: If your response endpoint renders an HTML page, any resources on that page will be able to see the authorization code in the URL. Scripts can read the URL directly, and the URL in the `Referer` HTTP header may be sent to any or all resources on the page.
237237
>
238238
> Carefully consider whether you want to send authorization credentials to all resources on that page (especially third-party scripts such as social plugins and analytics). To avoid this issue, we recommend that the server first handle the request, then redirect to another URL that doesn't include the response parameters.
239239

@@ -276,22 +276,22 @@ $access_token = $client->getAccessToken();
276276
Use the access token to call Google APIs by completing the following steps:
277277

278278
1. If you need to apply an access token to a new `Google_Client` object—for example, if you stored the access token in a user session—use the `setAccessToken` method:
279-
279+
280280
```php
281281
$client->setAccessToken($access_token);
282282
```
283-
283+
284284
2. Build a service object for the API that you want to call. You build a a service object by providing an authorized `Google_Client` object to the constructor for the API you want to call. For example, to call the Drive API:
285-
285+
286286
```php
287287
$drive = new Google_Service_Drive($client);
288288
```
289-
289+
290290
3. Make requests to the API service using the [interface provided by the service object](start.md). For example, to list the files in the authenticated user's Google Drive:
291-
291+
292292
```php
293293
$files = $drive->files->listFiles(array())->getItems();
294-
```
294+
```
295295

296296
[](#top_of_page)Complete example
297297
--------------------------------
@@ -302,24 +302,24 @@ To run this example:
302302

303303
1. In the API Console, add the URL of the local machine to the list of redirect URLs. For example, add `http://localhost:8080`.
304304
2. Create a new directory and change to it. For example:
305-
305+
306306
```sh
307307
mkdir ~/php-oauth2-example
308308
cd ~/php-oauth2-example
309309
```
310-
310+
311311
3. Install the [Google API Client Library](https://github.com/google/google-api-php-client) for PHP using [Composer](https://getcomposer.org):
312-
312+
313313
```sh
314314
composer require google/apiclient:^2.0
315315
```
316-
316+
317317
4. Create the files `index.php` and `oauth2callback.php` with the content below.
318318
5. Run the example with a web server configured to serve PHP. If you use PHP 5.4 or newer, you can use PHP's built-in test web server:
319-
319+
320320
```sh
321321
php -S localhost:8080 ~/php-oauth2-example
322-
```
322+
```
323323

324324
#### index.php
325325

0 commit comments

Comments
 (0)