Skip to content

Commit 9cc143d

Browse files
committed
next
1 parent 8596bdd commit 9cc143d

17 files changed

Lines changed: 667 additions & 1033 deletions

File tree

config/config.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
<?php
22

33
return [
4-
'default' => 'admin',
5-
'apps' => [
4+
'stores' => [
65
'admin' => [
6+
'sso' => [
7+
'enable' => false,
8+
],
79
'token' => [
8-
'uniqidKey' => 'uid',
9-
'signerKey' => '',
10-
'notBefore' => 0,
11-
'expiresAt' => 3600,
12-
'refreshTTL' => 7200,
10+
'unique_id_key' => 'uid',
11+
'signer_key' => 'tant',
12+
'not_before' => 0,
13+
'expires_at' => 3600,
14+
'refresh_ttL' => 7200,
1315
'signer' => 'Lcobucci\JWT\Signer\Hmac\Sha256',
1416
'type' => 'Header',
15-
'refresh' => 50001,
16-
'relogin' => 50002,
17+
'relogin_code' => 50001,
18+
'refresh_code' => 50002,
1719
'iss' => 'client.tant',
1820
'aud' => 'server.tant',
19-
'automaticRenewal' => false,
21+
'automatic_renewal' => false,
2022
],
2123
'user' => [
2224
'bind' => false,
23-
'model' => '',
25+
'class' => null,
2426
]
2527
]
2628
],

src/Config/Manager.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare (strict_types = 1);
4+
5+
namespace xiaodi\JWTAuth\Config;
6+
7+
class Manager
8+
{
9+
protected $prefix = 'jwt';
10+
protected $blacklist = 'blacklist';
11+
protected $whitelist = 'whitelist';
12+
13+
public function __construct(array $options = [])
14+
{
15+
if (!empty($options)) {
16+
foreach ($options as $key => $value) {
17+
$this->$key = $value;
18+
}
19+
}
20+
}
21+
22+
public function getPrefix(): string
23+
{
24+
return $this->prefix;
25+
}
26+
27+
public function getBlacklist(): string
28+
{
29+
return $this->blacklist;
30+
}
31+
32+
public function getWhitelist(): string
33+
{
34+
return $this->whitelist;
35+
}
36+
}

src/Config/SSO.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare (strict_types = 1);
4+
5+
namespace xiaodi\JWTAuth\Config;
6+
7+
class SSO
8+
{
9+
protected $enable = false;
10+
11+
public function __construct(array $options)
12+
{
13+
if (!empty($options)) {
14+
foreach ($options as $key => $value) {
15+
$this->$key = $value;
16+
}
17+
}
18+
}
19+
20+
public function getEnable(): bool
21+
{
22+
return $this->enable;
23+
}
24+
}

src/Config/Token.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare (strict_types = 1);
4+
5+
namespace xiaodi\JWTAuth\Config;
6+
7+
use Lcobucci\JWT\Signer;
8+
use Lcobucci\JWT\Signer\Key;
9+
use xiaodi\JWTAuth\Exception\JWTException;
10+
use think\App;
11+
12+
class Token
13+
{
14+
protected $unique_id_key = 'uid';
15+
protected $signer_key = null;
16+
protected $not_before = 0;
17+
protected $expires_at = 3600;
18+
protected $refresh_ttL = 7200;
19+
protected $signer = \Lcobucci\JWT\Signer\Hmac\Sha256::class;
20+
protected $type = 'Header';
21+
protected $relogin_code = 50002;
22+
protected $refresh_code = 50001;
23+
protected $iss = 'client.xiaodim.com';
24+
protected $aud = 'server.xiaodim.com';
25+
protected $automatic_renewal = false;
26+
27+
public function __construct(array $options)
28+
{
29+
if (!empty($options)) {
30+
foreach ($options as $key => $value) {
31+
$this->$key = $value;
32+
}
33+
}
34+
}
35+
36+
public function makeSignerKey()
37+
{
38+
$key = $this->signer_key;
39+
if (empty($key)) {
40+
throw new JWTException('config signer_key required.', 500);
41+
}
42+
43+
return new Key($key);
44+
}
45+
46+
public function getIdKey(): string
47+
{
48+
return $this->unique_id_key;
49+
}
50+
51+
public function getExpires()
52+
{
53+
return $this->expires_at;
54+
}
55+
56+
public function getRefreshTTL()
57+
{
58+
return $this->refresh_ttL;
59+
}
60+
61+
public function getIss(): string
62+
{
63+
return $this->iss;
64+
}
65+
66+
public function getAud(): string
67+
{
68+
return $this->aud;
69+
}
70+
71+
public function getNotBefore()
72+
{
73+
return $this->not_before;
74+
}
75+
76+
public function getSigner(): Signer
77+
{
78+
return new $this->signer;
79+
}
80+
81+
public function getReloginCode()
82+
{
83+
return $this->relogin_code;
84+
}
85+
86+
public function getAutomaticRenewal()
87+
{
88+
return $this->automatic_renewal;
89+
}
90+
91+
}

src/Config/User.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare (strict_types = 1);
4+
5+
namespace xiaodi\JWTAuth\Config;
6+
7+
class User
8+
{
9+
protected $bind = false;
10+
11+
protected $class = null;
12+
13+
public function __construct(array $options)
14+
{
15+
if (!empty($options)) {
16+
foreach ($options as $key => $value) {
17+
$this->$key = $value;
18+
}
19+
}
20+
}
21+
22+
public function getBind(): bool
23+
{
24+
return $this->bind;
25+
}
26+
27+
public function getClass()
28+
{
29+
return $this->class;
30+
}
31+
}

src/Facade/Jwt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class Jwt extends Facade
1919
*/
2020
protected static function getFacadeClass()
2121
{
22-
return 'jwt';
22+
return \xiaodi\JWTAuth\JwtAuth::class;
2323
}
2424
}

0 commit comments

Comments
 (0)