File tree Expand file tree Collapse file tree 7 files changed +16
-7
lines changed
Expand file tree Collapse file tree 7 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 77 "license" : " Apache-2.0" ,
88 "require" : {
99 "php" : " ^7.4|^8.0" ,
10- "google/auth" : " ^1.26 " ,
10+ "google/auth" : " ^1.28 " ,
1111 "google/apiclient-services" : " ~0.200" ,
1212 "firebase/php-jwt" : " ~6.0" ,
1313 "monolog/monolog" : " ^2.9||^3.0" ,
Original file line number Diff line number Diff line change 5757 * bundle in the session, and redirect to ourself.
5858 ************************************************/
5959if (isset ($ _GET ['code ' ])) {
60- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
60+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
6161
6262 // store in the session also
6363 $ _SESSION ['id_token_token ' ] = $ token ;
7777) {
7878 $ client ->setAccessToken ($ _SESSION ['id_token_token ' ]);
7979} else {
80+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
8081 $ authUrl = $ client ->createAuthUrl ();
8182}
8283
Original file line number Diff line number Diff line change 4848 * bundle in the session, and redirect to ourself.
4949 ************************************************/
5050if (isset ($ _GET ['code ' ])) {
51- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
51+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
5252 $ client ->setAccessToken ($ token );
5353
5454 // store in the session also
6565 unset($ _SESSION ['upload_token ' ]);
6666 }
6767} else {
68+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
6869 $ authUrl = $ client ->createAuthUrl ();
6970}
7071
Original file line number Diff line number Diff line change 5353 * bundle in the session, and redirect to ourself.
5454 ************************************************/
5555if (isset ($ _GET ['code ' ])) {
56- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
56+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
5757 $ client ->setAccessToken ($ token );
5858
5959 // store in the session also
7070 unset($ _SESSION ['upload_token ' ]);
7171 }
7272} else {
73+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
7374 $ authUrl = $ client ->createAuthUrl ();
7475}
7576
Original file line number Diff line number Diff line change 5454 * bundle in the session, and redirect to ourself.
5555 ************************************************/
5656if (isset ($ _GET ['code ' ])) {
57- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
57+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
5858 $ client ->setAccessToken ($ token );
5959
6060 // store in the session also
7171 unset($ _SESSION ['multi-api-token ' ]);
7272 }
7373} else {
74+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
7475 $ authUrl = $ client ->createAuthUrl ();
7576}
7677
Original file line number Diff line number Diff line change 5353 * bundle in the session, and redirect to ourself.
5454 ************************************************/
5555if (isset ($ _GET ['code ' ])) {
56- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
56+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
5757 $ client ->setAccessToken ($ token );
5858
5959 // store in the session also
7070 unset($ _SESSION ['upload_token ' ]);
7171 }
7272} else {
73+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
7374 $ authUrl = $ client ->createAuthUrl ();
7475}
7576
Original file line number Diff line number Diff line change @@ -240,9 +240,10 @@ public function authenticate($code)
240240 * Helper wrapped around the OAuth 2.0 implementation.
241241 *
242242 * @param string $code code from accounts.google.com
243+ * @param string $codeVerifier the code verifier used for PKCE (if applicable)
243244 * @return array access token
244245 */
245- public function fetchAccessTokenWithAuthCode ($ code )
246+ public function fetchAccessTokenWithAuthCode ($ code, $ codeVerifier = null )
246247 {
247248 if (strlen ($ code ) == 0 ) {
248249 throw new InvalidArgumentException ("Invalid code " );
@@ -251,6 +252,9 @@ public function fetchAccessTokenWithAuthCode($code)
251252 $ auth = $ this ->getOAuth2Service ();
252253 $ auth ->setCode ($ code );
253254 $ auth ->setRedirectUri ($ this ->getRedirectUri ());
255+ if ($ codeVerifier ) {
256+ $ auth ->setCodeVerifier ($ codeVerifier );
257+ }
254258
255259 $ httpHandler = HttpHandlerFactory::build ($ this ->getHttpClient ());
256260 $ creds = $ auth ->fetchAuthToken ($ httpHandler );
You can’t perform that action at this time.
0 commit comments