Skip to content

Commit 09bb0d8

Browse files
authored
Update readme.md
1 parent 279ed42 commit 09bb0d8

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

readme.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
## OAuth2 Server for Hyperf Framework
22

3-
4-
53
### installation
64

75
```
86
composer require xtwoend/oauth-server
97
```
108

11-
129
### Run on terminal
1310

1411
```
1512
php bin/hyperf.php vendor:publish xtwoend/oauth-server
16-
13+
1714
php bin/hyperf.php migrate
1815
1916
php bin/hyperf.php oauth:key
2017
2118
```
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+
```

0 commit comments

Comments
 (0)