File tree Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change 1
1
## OAuth2 Server for Hyperf Framework
2
2
3
-
4
-
5
3
### installation
6
4
7
5
```
8
6
composer require xtwoend/oauth-server
9
7
```
10
8
11
-
12
9
### Run on terminal
13
10
14
11
```
15
12
php bin/hyperf.php vendor:publish xtwoend/oauth-server
16
-
13
+
17
14
php bin/hyperf.php migrate
18
15
19
16
php bin/hyperf.php oauth:key
20
17
21
18
```
19
+
20
+ ### 创建app_client
21
+
22
+ ``` php
23
+ $userId = $request->input('user_id',1);
24
+ $length = 32; // 设置密钥长度
25
+ $clientSecret = bin2hex(random_bytes($length)); // 使用 random_bytes 函数生成随机的二进制字符串,并将其转换为十六进制表示形式
26
+ Db::table('oauth_clients')->insert([
27
+ 'user_id' => $userId,
28
+ 'project_id' => 0,
29
+ 'name' => 'default',
30
+ 'secret' => $clientSecret,
31
+ 'created_at' => date("Y-m-d H:i:s")
32
+ ]);
33
+ return $clientSecret;
34
+
35
+ ```
36
+
37
+ ### 测试获取 token
38
+
39
+ ```
40
+ curl --location --request POST 'http://127.0.0.1/oauth/token' \
41
+ --header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
42
+ --header 'Content-Type: application/json' \
43
+ --header 'Accept: */*' \
44
+ --header 'Connection: keep-alive' \
45
+ --data-raw '{
46
+ "grant_type":"client_credentials",
47
+ "client_id":1,
48
+ "client_secret":"6f818639a2944ac2f88df1174386f39e08e963a3fd8af64c5ca59e597ea5bddb"
49
+ }'
50
+ ```
You can’t perform that action at this time.
0 commit comments