File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -422,6 +422,28 @@ $client->setHttpClient($httpClient);
422422
423423Other Guzzle features such as [ Handlers and Middleware] ( http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html ) offer even more control.
424424
425+ ### Partial Consent and Granted Scopes
426+
427+ When using OAuth2 3LO (e.g. you're a client requesting credentials from a 3rd
428+ party, such as in the [ simple file upload example] ( examples/simple-file-upload.php ) ),
429+ you may want to take advantage of Partial Consent.
430+
431+ To allow clients to only grant certain scopes in the OAuth2 screen, pass the
432+ querystring parameter for ` enable_serial_consent ` when generating the
433+ authorization URL:
434+
435+ ``` php
436+ $authUrl = $client->createAuthUrl($scope, ['enable_serial_consent' => 'true']);
437+ ```
438+
439+ Once the flow is completed, you can see which scopes were granted by calling
440+ ` getGrantedScope ` on the OAuth2 object:
441+
442+ ``` php
443+ // Space-separated string of granted scopes if it exists, otherwise null.
444+ echo $client->getOAuth2Service()->getGrantedScope();
445+ ```
446+
425447### Service Specific Examples ###
426448
427449YouTube: https://github.com/youtube/api-samples/tree/master/php
Original file line number Diff line number Diff line change @@ -357,9 +357,10 @@ public function fetchAccessTokenWithRefreshToken($refreshToken = null)
357357 * The authorization endpoint allows the user to first
358358 * authenticate, and then grant/deny the access request.
359359 * @param string|array $scope The scope is expressed as an array or list of space-delimited strings.
360+ * @param array $queryParams Querystring params to add to the authorization URL.
360361 * @return string
361362 */
362- public function createAuthUrl ($ scope = null )
363+ public function createAuthUrl ($ scope = null , array $ queryParams = [] )
363364 {
364365 if (empty ($ scope )) {
365366 $ scope = $ this ->prepareScopes ();
@@ -390,7 +391,7 @@ public function createAuthUrl($scope = null)
390391 'response_type ' => 'code ' ,
391392 'scope ' => $ scope ,
392393 'state ' => $ this ->config ['state ' ],
393- ]);
394+ ]) + $ queryParams ;
394395
395396 // If the list of scopes contains plus.login, add request_visible_actions
396397 // to auth URL.
Original file line number Diff line number Diff line change @@ -1025,4 +1025,14 @@ public function testSetNewRedirectUri()
10251025 $ authUrl2 = $ client ->createAuthUrl ();
10261026 $ this ->assertStringContainsString (urlencode ($ redirectUri2 ), $ authUrl2 );
10271027 }
1028+
1029+ public function testQueryParamsForAuthUrl ()
1030+ {
1031+ $ client = new Client ();
1032+ $ client ->setRedirectUri ('https://example.com ' );
1033+ $ authUrl1 = $ client ->createAuthUrl (null , [
1034+ 'enable_serial_consent ' => 'true '
1035+ ]);
1036+ $ this ->assertStringContainsString ('&enable_serial_consent=true ' , $ authUrl1 );
1037+ }
10281038}
You can’t perform that action at this time.
0 commit comments