File tree 7 files changed +16
-7
lines changed
7 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 7
7
"license" : " Apache-2.0" ,
8
8
"require" : {
9
9
"php" : " ^7.4|^8.0" ,
10
- "google/auth" : " ^1.26 " ,
10
+ "google/auth" : " ^1.28 " ,
11
11
"google/apiclient-services" : " ~0.200" ,
12
12
"firebase/php-jwt" : " ~6.0" ,
13
13
"monolog/monolog" : " ^2.9||^3.0" ,
Original file line number Diff line number Diff line change 57
57
* bundle in the session, and redirect to ourself.
58
58
************************************************/
59
59
if (isset ($ _GET ['code ' ])) {
60
- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
60
+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
61
61
62
62
// store in the session also
63
63
$ _SESSION ['id_token_token ' ] = $ token ;
77
77
) {
78
78
$ client ->setAccessToken ($ _SESSION ['id_token_token ' ]);
79
79
} else {
80
+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
80
81
$ authUrl = $ client ->createAuthUrl ();
81
82
}
82
83
Original file line number Diff line number Diff line change 48
48
* bundle in the session, and redirect to ourself.
49
49
************************************************/
50
50
if (isset ($ _GET ['code ' ])) {
51
- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
51
+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
52
52
$ client ->setAccessToken ($ token );
53
53
54
54
// store in the session also
65
65
unset($ _SESSION ['upload_token ' ]);
66
66
}
67
67
} else {
68
+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
68
69
$ authUrl = $ client ->createAuthUrl ();
69
70
}
70
71
Original file line number Diff line number Diff line change 53
53
* bundle in the session, and redirect to ourself.
54
54
************************************************/
55
55
if (isset ($ _GET ['code ' ])) {
56
- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
56
+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
57
57
$ client ->setAccessToken ($ token );
58
58
59
59
// store in the session also
70
70
unset($ _SESSION ['upload_token ' ]);
71
71
}
72
72
} else {
73
+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
73
74
$ authUrl = $ client ->createAuthUrl ();
74
75
}
75
76
Original file line number Diff line number Diff line change 54
54
* bundle in the session, and redirect to ourself.
55
55
************************************************/
56
56
if (isset ($ _GET ['code ' ])) {
57
- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
57
+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
58
58
$ client ->setAccessToken ($ token );
59
59
60
60
// store in the session also
71
71
unset($ _SESSION ['multi-api-token ' ]);
72
72
}
73
73
} else {
74
+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
74
75
$ authUrl = $ client ->createAuthUrl ();
75
76
}
76
77
Original file line number Diff line number Diff line change 53
53
* bundle in the session, and redirect to ourself.
54
54
************************************************/
55
55
if (isset ($ _GET ['code ' ])) {
56
- $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ]);
56
+ $ token = $ client ->fetchAccessTokenWithAuthCode ($ _GET ['code ' ], $ _SESSION [ ' code_verifier ' ] );
57
57
$ client ->setAccessToken ($ token );
58
58
59
59
// store in the session also
70
70
unset($ _SESSION ['upload_token ' ]);
71
71
}
72
72
} else {
73
+ $ _SESSION ['code_verifier ' ] = $ client ->getOAuth2Service ()->generateCodeVerifier ();
73
74
$ authUrl = $ client ->createAuthUrl ();
74
75
}
75
76
Original file line number Diff line number Diff line change @@ -240,9 +240,10 @@ public function authenticate($code)
240
240
* Helper wrapped around the OAuth 2.0 implementation.
241
241
*
242
242
* @param string $code code from accounts.google.com
243
+ * @param string $codeVerifier the code verifier used for PKCE (if applicable)
243
244
* @return array access token
244
245
*/
245
- public function fetchAccessTokenWithAuthCode ($ code )
246
+ public function fetchAccessTokenWithAuthCode ($ code, $ codeVerifier = null )
246
247
{
247
248
if (strlen ($ code ) == 0 ) {
248
249
throw new InvalidArgumentException ("Invalid code " );
@@ -251,6 +252,9 @@ public function fetchAccessTokenWithAuthCode($code)
251
252
$ auth = $ this ->getOAuth2Service ();
252
253
$ auth ->setCode ($ code );
253
254
$ auth ->setRedirectUri ($ this ->getRedirectUri ());
255
+ if ($ codeVerifier ) {
256
+ $ auth ->setCodeVerifier ($ codeVerifier );
257
+ }
254
258
255
259
$ httpHandler = HttpHandlerFactory::build ($ this ->getHttpClient ());
256
260
$ creds = $ auth ->fetchAuthToken ($ httpHandler );
You can’t perform that action at this time.
0 commit comments