|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of OAuth 2.0 Laravel. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Luca Degasperi <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LucaDegasperi\OAuth2Server\Storage; |
|
13
|
|
|
|
|
14
|
|
|
use Carbon\Carbon; |
|
15
|
|
|
use League\OAuth2\Server\Entity\RefreshTokenEntity; |
|
16
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* This is the fluent refresh token class. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Luca Degasperi <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class FluentRefreshToken extends AbstractFluentAdapter implements RefreshTokenInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $token |
|
29
|
|
|
* |
|
30
|
|
|
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
9 |
View Code Duplication |
public function get($token) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
9 |
|
$result = $this->getConnection()->table('oauth_refresh_tokens') |
|
35
|
9 |
|
->where('oauth_refresh_tokens.id', $token) |
|
36
|
9 |
|
->where('oauth_refresh_tokens.expire_time', '>=', time()) |
|
37
|
9 |
|
->first(); |
|
38
|
|
|
|
|
39
|
9 |
|
if (is_null($result)) { |
|
40
|
6 |
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
3 |
|
return (new RefreshTokenEntity($this->getServer())) |
|
44
|
3 |
|
->setId($result->id) |
|
45
|
3 |
|
->setAccessTokenId($result->access_token_id) |
|
46
|
3 |
|
->setExpireTime((int) $result->expire_time); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create a new refresh token_name. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $token |
|
53
|
|
|
* @param int $expireTime |
|
54
|
|
|
* @param string $accessToken |
|
55
|
|
|
* |
|
56
|
|
|
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity |
|
57
|
|
|
*/ |
|
58
|
3 |
View Code Duplication |
public function create($token, $expireTime, $accessToken) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
3 |
|
$this->getConnection()->table('oauth_refresh_tokens')->insert([ |
|
61
|
3 |
|
'id' => $token, |
|
62
|
3 |
|
'expire_time' => $expireTime, |
|
63
|
3 |
|
'access_token_id' => $accessToken, |
|
64
|
3 |
|
'created_at' => Carbon::now(), |
|
65
|
3 |
|
'updated_at' => Carbon::now(), |
|
66
|
3 |
|
]); |
|
67
|
|
|
|
|
68
|
3 |
|
return (new RefreshTokenEntity($this->getServer())) |
|
69
|
3 |
|
->setId($token) |
|
70
|
3 |
|
->setAccessTokenId($accessToken) |
|
71
|
3 |
|
->setExpireTime((int) $expireTime); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Delete the refresh token. |
|
76
|
|
|
* |
|
77
|
|
|
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $token |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function delete(RefreshTokenEntity $token) |
|
82
|
|
|
{ |
|
83
|
3 |
|
$this->getConnection()->table('oauth_refresh_tokens') |
|
84
|
3 |
|
->where('id', $token->getId()) |
|
85
|
3 |
|
->delete(); |
|
86
|
3 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.