Skip to content

Commit 7f3fa3a

Browse files
committed
fix: markdown
1 parent 323d7db commit 7f3fa3a

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

README.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ Socialite 是一个 [OAuth2](https://oauth.net/2/) 认证工具。 它的灵感
1212

1313
如果你喜欢我的项目并想支持我,[点击这里 :heart:](https://github.com/sponsors/overtrue)
1414

15-
# 版本要求
15+
## 版本要求
1616

17-
```
1817
PHP >= 8.0.2
19-
```
2018

21-
# 安装
19+
## 安装
2220

2321
```shell
24-
$ composer require "overtrue/socialite" -vvv
22+
composer require "overtrue/socialite" -vvv
2523
```
2624

27-
# 使用指南
25+
## 使用指南
2826

2927
用户只需要创建相应配置变量,然后通过工具为各个平台创建认证应用,并轻松获取该平台的 access_token 和用户相关信息。工具实现逻辑详见参照各大平台 OAuth2 文档。
3028

@@ -117,18 +115,18 @@ $config = [
117115
$config = [
118116
// 为 github 应用起别名为 foo
119117
'foo' => [
120-
'provider' => 'github', // <-- provider name
121-
'client_id' => 'your-app-id',
118+
'provider' => 'github', // <-- provider name
119+
'client_id' => 'your-app-id',
122120
'client_secret' => 'your-app-secret',
123-
'redirect' => 'http://localhost/socialite/callback.php',
121+
'redirect' => 'http://localhost/socialite/callback.php',
124122
],
125123

126124
// 另外一个名字叫做 bar 的 github 应用
127125
'bar' => [
128-
'provider' => 'github', // <-- provider name
129-
'client_id' => 'your-app-id',
126+
'provider' => 'github', // <-- provider name
127+
'client_id' => 'your-app-id',
130128
'client_secret' => 'your-app-secret',
131-
'redirect' => 'http://localhost/socialite/callback.php',
129+
'redirect' => 'http://localhost/socialite/callback.php',
132130
],
133131

134132
//...
@@ -167,9 +165,10 @@ $socialite->extend('myprovider', function(array $config) {
167165
$app = $socialite->create('foo');
168166
```
169167

170-
2. 使用服务提供类
168+
1. 使用服务提供类
171169

172-
>👋🏻 你的自定义服务提供类必须实现`Overtrue\Socialite\Contracts\ProviderInterface` 接口
170+
> {WARNING}
171+
> 👋🏻 你的自定义服务提供类必须实现 `Overtrue\Socialite\Contracts\ProviderInterface` 接口
173172
174173
```php
175174
class MyCustomProvider implements \Overtrue\Socialite\Contracts\ProviderInterface
@@ -183,19 +182,17 @@ class MyCustomProvider implements \Overtrue\Socialite\Contracts\ProviderInterfac
183182
```php
184183
$config = [
185184
'foo' => [
186-
'provider' => MyCustomProvider::class, // <-- 类名
187-
'client_id' => 'your-app-id',
185+
'provider' => MyCustomProvider::class, // <-- 类名
186+
'client_id' => 'your-app-id',
188187
'client_secret' => 'your-app-secret',
189-
'redirect' => 'http://localhost/socialite/callback.php',
188+
'redirect' => 'http://localhost/socialite/callback.php',
190189
],
191190
];
192191

193192
$socialite = new SocialiteManager($config);
194193
$app = $socialite->create('foo');
195194
```
196195

197-
198-
199196
## 平台
200197

201198
不同的平台有不同的配置方法,为了确保工具的正常运行,所以请确保你所使用的平台的配置都是如期设置的。
@@ -332,7 +329,6 @@ $user = $socialite->create('xigua')->userFromCode('here is auth code');
332329
$user = $socialite->create('xigua')->withOpenId('openId')->userFromToken('here is the access token');
333330
```
334331

335-
336332
### [百度](https://developer.baidu.com/wiki/index.php?title=docs/oauth)
337333

338334
其他配置没啥区别,在用法上,可以很轻易的选择重定向登录页面的模式,通过 `withDisplay()`
@@ -432,9 +428,9 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
432428
[
433429
'wechat' =>
434430
[
435-
'client_id' => 'client_id',
431+
'client_id' => 'client_id',
436432
'client_secret' => 'client_secret',
437-
'redirect' => 'redirect-url',
433+
'redirect' => 'redirect-url',
438434

439435
// 开放平台 - 第三方平台所需
440436
'component' => [
@@ -448,7 +444,6 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
448444
...
449445
```
450446

451-
452447
### [Coding](https://coding.net/help/openapi#oauth)
453448

454449
您需要额外配置 `team_url` 为您的团队域名,例如:
@@ -468,8 +463,7 @@ $config = [
468463

469464
您可能需要设置responseType,可以使用`withResponseType`函数进行设置,默认是`code` 还可以设置为`id_token``code` & `id_token`
470465

471-
> https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/
472-
466+
> <https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/>
473467
474468
```php
475469
$config = [
@@ -562,10 +556,9 @@ $response = $socialite->create('google')
562556
->with(['hd' => 'example.com'])->redirect();
563557
```
564558

565-
566559
## User interface
567560

568-
### 标准的 user api
561+
### 标准的 user api
569562

570563
```php
571564
$user = $socialite->create('github')->userFromCode($code);
@@ -622,15 +615,15 @@ mixed $user->getId();
622615

623616
```
624617

625-
### 从 OAuth API 响应中取得原始数据
618+
### 从 OAuth API 响应中取得原始数据
626619

627620
`$user->getRaw()` 方法会返回一个 **array**
628621

629622
### 当你使用 userFromCode() 想要获取 token 响应的原始数据
630623

631624
`$user->getTokenResponse()` 方法会返回一个 **array** 里面是响应从获取 token 时候 API 返回的响应。
632625

633-
> 注意:当你使用 `userFromCode()` 时,这个方法只返回一个 **有效的数组**,否则将返回 **null**,因为 `userFromToken() ` 没有 token 的 HTTP 响应。
626+
> 注意:当你使用 `userFromCode()` 时,这个方法只返回一个 **有效的数组**,否则将返回 **null**,因为 `userFromToken()` 没有 token 的 HTTP 响应。
634627
635628
### 通过 access token 获取用户信息
636629

@@ -639,11 +632,9 @@ $accessToken = 'xxxxxxxxxxx';
639632
$user = $socialite->userFromToken($accessToken);
640633
```
641634

635+
## Enjoy it! :heart:
642636

643-
644-
# Enjoy it! :heart:
645-
646-
# 参照
637+
## 参照
647638

648639
- [Alipay - 用户信息授权](https://opendocs.alipay.com/open/289/105656)
649640
- [DingTalk - 扫码登录第三方网站](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3)
@@ -668,14 +659,12 @@ $user = $socialite->userFromToken($accessToken);
668659
- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)
669660
- [PayPal - OAuth文档](https://developer.paypal.com/docs/log-in-with-paypal/)
670661

671-
672-
673-
# PHP 扩展包开发
662+
## PHP 扩展包开发
674663

675664
> 想知道如何从零开始构建 PHP 扩展包?
676665
>
677666
> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)
678667
679-
# License
668+
## License
680669

681670
MIT

0 commit comments

Comments
 (0)