forked from jianyan74/rageframe2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessTokenService.php
74 lines (67 loc) · 1.85 KB
/
AccessTokenService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace services\oauth2;
use common\models\oauth2\AccessToken;
use common\components\Service;
/**
* Class AccessTokenService
* @package services\oauth2
* @author jianyan74 <[email protected]>
*/
class AccessTokenService extends Service
{
/**
* @param $client_id
* @param $grant_type
* @param $access_token
* @param $expires
* @param $member_id
* @param $scopes
*/
public function create($client_id, $grant_type, $access_token, $expires, $member_id, $scopes)
{
if (!($model = $this->findByClientId($client_id, $grant_type, $member_id))) {
$model = new AccessToken();
$model->client_id = $client_id;
$model->grant_type = $grant_type;
$model->member_id = (string)$member_id;
}
$model->expires = $expires;
$model->access_token = $access_token;
$model->scope = $scopes;
$model->save();
}
/**
* @param $tokenId
*/
public function deleteByAccessToken($tokenId)
{
AccessToken::deleteAll(['access_token' => $tokenId]);
}
/**
* @param $tokenId
* @param string $client_id
* @return array|\yii\db\ActiveRecord|null
*/
public function findByAccessToken($tokenId, $client_id = '')
{
return AccessToken::find()
->where(['access_token' => $tokenId])
->andFilterWhere(['client_id' => $client_id])
->one();
}
/**
* @param $client_id
* @param $grant_type
* @return array|\yii\db\ActiveRecord|null
*/
public function findByClientId($client_id, $grant_type, $member_id)
{
return AccessToken::find()
->where([
'client_id' => $client_id,
'grant_type' => $grant_type,
'member_id' => $member_id,
])
->one();
}
}