Skip to content

Commit f84c759

Browse files
authored
[codex] Support redirect_uri config in Google userFromCode flow (#303)
* support redirect_uri alias in google provider * normalize redirect_uri alias in base provider * normalize redirect aliases to redirect_uri * update README examples to use redirect_uri * apply pint formatting for ci stability
1 parent 2ec6472 commit f84c759

File tree

14 files changed

+201
-94
lines changed

14 files changed

+201
-94
lines changed

README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $config = [
4646
'github' => [
4747
'client_id' => 'your-app-id',
4848
'client_secret' => 'your-app-secret',
49-
'redirect' => 'http://localhost/socialite/callback.php',
49+
'redirect_uri' => 'http://localhost/socialite/callback.php',
5050
],
5151
];
5252

@@ -68,7 +68,7 @@ $config = [
6868
'github' => [
6969
'client_id' => 'your-app-id',
7070
'client_secret' => 'your-app-secret',
71-
'redirect' => 'http://localhost/socialite/callback.php',
71+
'redirect_uri' => 'http://localhost/socialite/callback.php',
7272
],
7373
];
7474

@@ -88,7 +88,8 @@ $user->getEmail(); // "anzhengchao@gmail.com"
8888

8989
## 配置
9090

91-
为每个平台设置相同的键值对后就能开箱即用:`client_id`, `client_secret`, `redirect`.
91+
为每个平台设置相同的键值对后就能开箱即用:`client_id`, `client_secret`, `redirect_uri`
92+
同时兼容旧键名:`redirect``redirect_url`
9293

9394
示例:
9495

@@ -97,12 +98,12 @@ $config = [
9798
'weibo' => [
9899
'client_id' => 'your-app-id',
99100
'client_secret' => 'your-app-secret',
100-
'redirect' => 'http://localhost/socialite/callback.php',
101+
'redirect_uri' => 'http://localhost/socialite/callback.php',
101102
],
102103
'facebook' => [
103104
'client_id' => 'your-app-id',
104105
'client_secret' => 'your-app-secret',
105-
'redirect' => 'http://localhost/socialite/callback.php',
106+
'redirect_uri' => 'http://localhost/socialite/callback.php',
106107
],
107108
];
108109
```
@@ -118,15 +119,15 @@ $config = [
118119
'provider' => 'github', // <-- provider name
119120
'client_id' => 'your-app-id',
120121
'client_secret' => 'your-app-secret',
121-
'redirect' => 'http://localhost/socialite/callback.php',
122+
'redirect_uri' => 'http://localhost/socialite/callback.php',
122123
],
123124

124125
// 另外一个名字叫做 bar 的 github 应用
125126
'bar' => [
126127
'provider' => 'github', // <-- provider name
127128
'client_id' => 'your-app-id',
128129
'client_secret' => 'your-app-secret',
129-
'redirect' => 'http://localhost/socialite/callback.php',
130+
'redirect_uri' => 'http://localhost/socialite/callback.php',
130131
],
131132

132133
//...
@@ -152,7 +153,7 @@ $config = [
152153
'provider' => 'myprovider', // <-- 一个工具还未支持的服务提供程序
153154
'client_id' => 'your-app-id',
154155
'client_secret' => 'your-app-secret',
155-
'redirect' => 'http://localhost/socialite/callback.php',
156+
'redirect_uri' => 'http://localhost/socialite/callback.php',
156157
],
157158
];
158159

@@ -186,7 +187,7 @@ $config = [
186187
'provider' => MyCustomProvider::class, // <-- 类名
187188
'client_id' => 'your-app-id',
188189
'client_secret' => 'your-app-secret',
189-
'redirect' => 'http://localhost/socialite/callback.php',
190+
'redirect_uri' => 'http://localhost/socialite/callback.php',
190191
],
191192
];
192193

@@ -215,8 +216,8 @@ $config = [
215216
'rsa_private_key' => 'your-rsa-private-key',
216217

217218
// 确保这里的值与你在服务后台绑定的地址值一致
218-
// 这个键名还能像官方文档那样叫做 'redirect_url'
219-
'redirect' => 'http://localhost/socialite/callback.php',
219+
// 推荐使用 'redirect_uri',同时兼容 'redirect' 与 'redirect_url'
220+
'redirect_uri' => 'http://localhost/socialite/callback.php',
220221

221222
// 沙箱模式接入地址见 https://opendocs.alipay.com/open/220/105337#%E5%85%B3%E4%BA%8E%E6%B2%99%E7%AE%B1
222223
'sandbox' => false,
@@ -253,8 +254,8 @@ $config = [
253254
// or 'app_secret'
254255
'client_secret' => 'your app secret',
255256

256-
// or 'redirect_url'
257-
'redirect' => 'redirect URL'
257+
// 兼容旧键名:'redirect' 或 'redirect_url'
258+
'redirect_uri' => 'redirect URL'
258259
]
259260
];
260261

@@ -281,7 +282,7 @@ $config = [
281282

282283
'client_secret' => 'your app secret',
283284

284-
'redirect' => 'redirect URL'
285+
'redirect_uri' => 'redirect URL'
285286
]
286287
];
287288

@@ -301,7 +302,7 @@ $config = [
301302
'toutiao' => [
302303
'client_id' => 'your app id',
303304
'client_secret' => 'your app secret',
304-
'redirect' => 'redirect URL'
305+
'redirect_uri' => 'redirect URL'
305306
]
306307
];
307308

@@ -320,7 +321,7 @@ $config = [
320321
'xigua' => [
321322
'client_id' => 'your app id',
322323
'client_secret' => 'your app secret',
323-
'redirect' => 'redirect URL'
324+
'redirect_uri' => 'redirect URL'
324325
]
325326
];
326327

@@ -361,8 +362,8 @@ $config = [
361362
// or 'app_secret'
362363
'client_secret' => 'your app secret',
363364

364-
// or 'redirect_url'
365-
'redirect' => 'redirect URL',
365+
// 兼容旧键名:'redirect' 或 'redirect_url'
366+
'redirect_uri' => 'redirect URL',
366367

367368
// 如果你想使用使用内部应用的方式获取 app_access_token
368369
// 对这个键设置了 'internal' 值那么你已经开启了内部应用模式
@@ -391,8 +392,8 @@ $config = [
391392
// or 'app_secret'
392393
'client_secret' => 'your app secret',
393394

394-
// or 'redirect_url'
395-
'redirect' => 'redirect URL',
395+
// 兼容旧键名:'redirect' 或 'redirect_url'
396+
'redirect_uri' => 'redirect URL',
396397

397398
// 如果你想使用使用内部应用的方式获取 app_access_token
398399
// 对这个键设置了 'internal' 值那么你已经开启了内部应用模式
@@ -431,7 +432,7 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
431432
[
432433
'client_id' => 'client_id',
433434
'client_secret' => 'client_secret',
434-
'redirect' => 'redirect-url',
435+
'redirect_uri' => 'redirect-url',
435436

436437
// 开放平台 - 第三方平台所需
437438
'component' => [
@@ -455,7 +456,7 @@ $config = [
455456
'team_url' => 'https://{your-team}.coding.net',
456457
'client_id' => 'your app id',
457458
'client_secret' => 'your app secret',
458-
'redirect' => 'redirect URL',
459+
'redirect_uri' => 'redirect URL',
459460
]
460461
];
461462
```
@@ -472,7 +473,7 @@ $config = [
472473
'client_id' => 'AT******************',
473474
'client_secret' => 'EK**************',
474475
'sandbox' => false,
475-
'redirect_url'=>"nativexo://paypalpay",
476+
'redirect_uri' => "nativexo://paypalpay",
476477
],
477478
];
478479
```
@@ -490,7 +491,7 @@ $config = [
490491
'team_id' => 'XXXXXXXXXX', // Apple Developer Team ID
491492
'key_id' => 'XXXXXXXXXX', // Key ID from Apple Developer
492493
'private_key' => file_get_contents('/path/to/AuthKey_XXXXXXXXXX.p8'), // .p8 private key content
493-
'redirect' => 'https://example.com/auth/apple/callback',
494+
'redirect_uri' => 'https://example.com/auth/apple/callback',
494495
],
495496
];
496497
```
@@ -508,7 +509,7 @@ $response = $socialite->create('github')
508509

509510
### Redirect URL
510511

511-
你也可以动态设置' redirect_uri ',你可以使用以下方法来改变 `redirect_uri` URL:
512+
你也可以动态设置 `redirect_uri`,你可以使用以下方法来改变 `redirect_uri` URL:
512513

513514
```php
514515
$url = 'your callback url.';

README_EN.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $config = [
4747
'github' => [
4848
'client_id' => 'your-app-id',
4949
'client_secret' => 'your-app-secret',
50-
'redirect' => 'http://localhost/socialite/callback.php',
50+
'redirect_uri' => 'http://localhost/socialite/callback.php',
5151
],
5252
];
5353

@@ -69,7 +69,7 @@ $config = [
6969
'github' => [
7070
'client_id' => 'your-app-id',
7171
'client_secret' => 'your-app-secret',
72-
'redirect' => 'http://localhost/socialite/callback.php',
72+
'redirect_uri' => 'http://localhost/socialite/callback.php',
7373
],
7474
];
7575

@@ -89,20 +89,21 @@ $user->getEmail(); // "anzhengchao@gmail.com"
8989

9090
## Configuration
9191

92-
Each create uses the same configuration keys: `client_id`, `client_secret`, `redirect`.
92+
Each provider uses the same configuration keys: `client_id`, `client_secret`, `redirect_uri`.
93+
Legacy aliases are still supported: `redirect`, `redirect_url`.
9394

9495
Example:
9596
```php
9697
$config = [
9798
'weibo' => [
9899
'client_id' => 'your-app-id',
99100
'client_secret' => 'your-app-secret',
100-
'redirect' => 'http://localhost/socialite/callback.php',
101+
'redirect_uri' => 'http://localhost/socialite/callback.php',
101102
],
102103
'facebook' => [
103104
'client_id' => 'your-app-id',
104105
'client_secret' => 'your-app-secret',
105-
'redirect' => 'http://localhost/socialite/callback.php',
106+
'redirect_uri' => 'http://localhost/socialite/callback.php',
106107
],
107108
];
108109
```
@@ -117,15 +118,15 @@ $config = [
117118
'provider' => 'github', // <-- provider name
118119
'client_id' => 'your-app-id',
119120
'client_secret' => 'your-app-secret',
120-
'redirect' => 'http://localhost/socialite/callback.php',
121+
'redirect_uri' => 'http://localhost/socialite/callback.php',
121122
],
122123

123124
// another github app
124125
'bar' => [
125126
'provider' => 'github', // <-- provider name
126127
'client_id' => 'your-app-id',
127128
'client_secret' => 'your-app-secret',
128-
'redirect' => 'http://localhost/socialite/callback.php',
129+
'redirect_uri' => 'http://localhost/socialite/callback.php',
129130
],
130131
//...
131132
];
@@ -144,7 +145,7 @@ $config = [
144145
'provider' => 'myprovider', // <-- provider name
145146
'client_id' => 'your-app-id',
146147
'client_secret' => 'your-app-secret',
147-
'redirect' => 'http://localhost/socialite/callback.php',
148+
'redirect_uri' => 'http://localhost/socialite/callback.php',
148149
],
149150
];
150151

@@ -176,7 +177,7 @@ $config = [
176177
'provider' => MyCustomProvider::class, // <-- class name
177178
'client_id' => 'your-app-id',
178179
'client_secret' => 'your-app-secret',
179-
'redirect' => 'http://localhost/socialite/callback.php',
180+
'redirect_uri' => 'http://localhost/socialite/callback.php',
180181
],
181182
];
182183

@@ -206,8 +207,8 @@ $config = [
206207
'rsa_private_key' => 'your-rsa-private-key',
207208

208209
// Be sure to set this value and make sure that it is the same address value as set in the official admin system.
209-
// This can also be named as 'redirect_url' like the official documentation.
210-
'redirect' => 'http://localhost/socialite/callback.php',
210+
// Recommended key: 'redirect_uri' (legacy aliases: 'redirect', 'redirect_url')
211+
'redirect_uri' => 'http://localhost/socialite/callback.php',
211212
]
212213
...
213214
];
@@ -240,8 +241,8 @@ $config = [
240241
// or 'app_secret'
241242
'client_secret' => 'your app secret',
242243

243-
// or 'redirect_url'
244-
'redirect' => 'redirect URL'
244+
// legacy aliases: 'redirect' or 'redirect_url'
245+
'redirect_uri' => 'redirect URL'
245246
]
246247
];
247248

@@ -268,7 +269,7 @@ $config = [
268269

269270
'client_secret' => 'your app secret',
270271

271-
'redirect' => 'redirect URL'
272+
'redirect_uri' => 'redirect URL'
272273
]
273274
];
274275

@@ -288,7 +289,7 @@ $config = [
288289
'toutiao' => [
289290
'client_id' => 'your app id',
290291
'client_secret' => 'your app secret',
291-
'redirect' => 'redirect URL'
292+
'redirect_uri' => 'redirect URL'
292293
]
293294
];
294295

@@ -307,7 +308,7 @@ $config = [
307308
'xigua' => [
308309
'client_id' => 'your app id',
309310
'client_secret' => 'your app secret',
310-
'redirect' => 'redirect URL'
311+
'redirect_uri' => 'redirect URL'
311312
]
312313
];
313314

@@ -348,8 +349,8 @@ $config = [
348349
// or 'app_secret'
349350
'client_secret' => 'your app secret',
350351

351-
// or 'redirect_url'
352-
'redirect' => 'redirect URL',
352+
// legacy aliases: 'redirect' or 'redirect_url'
353+
'redirect_uri' => 'redirect URL',
353354

354355
// if you want to use internal way to get app_access_token
355356
// set this key by 'internal' then you already turn on the internal app mode
@@ -378,8 +379,8 @@ $config = [
378379
// or 'app_secret'
379380
'client_secret' => 'your app secret',
380381

381-
// or 'redirect_url'
382-
'redirect' => 'redirect URL',
382+
// legacy aliases: 'redirect' or 'redirect_url'
383+
'redirect_uri' => 'redirect URL',
383384

384385
// if you want to use internal way to get app_access_token
385386
// set this key by 'internal' then you already turn on the internal app mode
@@ -416,7 +417,7 @@ You just need input your config like below config. Official Accounts authorizati
416417
[
417418
'client_id' => 'client_id',
418419
'client_secret' => 'client_secret',
419-
'redirect' => 'redirect-url',
420+
'redirect_uri' => 'redirect-url',
420421

421422
// Open Platform - Third-party Platform Need
422423
'component' => [
@@ -438,7 +439,7 @@ $config = [
438439
'team_url' => 'https://{your-team}.coding.net',
439440
'client_id' => 'your app id',
440441
'client_secret' => 'your app secret',
441-
'redirect' => 'redirect URL',
442+
'redirect_uri' => 'redirect URL',
442443
]
443444
];
444445
```
@@ -456,7 +457,7 @@ $config = [
456457
'client_id' => 'AT******************',
457458
'client_secret' => 'EK**************',
458459
'sandbox' => false,
459-
'redirect_url'=>"nativexo://paypalpay",
460+
'redirect_uri' => "nativexo://paypalpay",
460461
],
461462
];
462463
```
@@ -474,7 +475,7 @@ $config = [
474475
'team_id' => 'XXXXXXXXXX', // Apple Developer Team ID
475476
'key_id' => 'XXXXXXXXXX', // Key ID from Apple Developer
476477
'private_key' => file_get_contents('/path/to/AuthKey_XXXXXXXXXX.p8'), // .p8 private key content
477-
'redirect' => 'https://example.com/auth/apple/callback',
478+
'redirect_uri' => 'https://example.com/auth/apple/callback',
478479
],
479480
];
480481
```
@@ -494,7 +495,7 @@ $response = $socialite->create('github')
494495

495496
### Redirect URL
496497

497-
You may also want to dynamically set `redirect_uri`you can use the following methods to change the `redirect_uri` URL:
498+
You may also want to dynamically set `redirect_uri`, you can use the following methods to change the `redirect_uri` URL:
498499

499500
```php
500501
$url = 'your callback url.';

0 commit comments

Comments
 (0)