1 | <?php |
||
9 | class Authorization |
||
10 | { |
||
11 | const CACHE_KEY_ACCESS_TOKEN = 'EntWeChat.suite.authorizer_access_token'; |
||
12 | const CACHE_KEY_PERMANENT_CODE = 'EntWeChat.suite.authorizer_permanent_code'; |
||
13 | |||
14 | /** |
||
15 | * Cache. |
||
16 | * |
||
17 | * @var \Doctrine\Common\Cache\Cache |
||
18 | */ |
||
19 | protected $cache; |
||
20 | |||
21 | /** |
||
22 | * Base API. |
||
23 | * |
||
24 | * @var \EntWeChat\Suite\Api\BaseApi |
||
25 | */ |
||
26 | protected $api; |
||
27 | |||
28 | /** |
||
29 | * Suite Id. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $suiteId; |
||
34 | |||
35 | /** |
||
36 | * Authorizer Corp Id. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $authorizerCorpId; |
||
41 | |||
42 | /** |
||
43 | * Authorization Constructor. |
||
44 | * |
||
45 | * @param \EntWeChat\Suite\Api\BaseApi $api |
||
46 | * @param string $suiteId |
||
47 | * @param \Doctrine\Common\Cache\Cache $cache |
||
48 | */ |
||
49 | public function __construct(BaseApi $api, $suiteId, Cache $cache) |
||
55 | |||
56 | /** |
||
57 | * Gets the base api. |
||
58 | * |
||
59 | * @return \EntWeChat\Suite\Api\BaseApi |
||
60 | */ |
||
61 | public function getApi() |
||
65 | |||
66 | /** |
||
67 | * Saves the authorizer access token in cache. |
||
68 | * |
||
69 | * @param string $token |
||
70 | * |
||
71 | * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise |
||
72 | */ |
||
73 | public function setAuthorizerAccessToken($token, $expires = 7200) |
||
77 | |||
78 | /** |
||
79 | * Gets the authorizer access token cache key. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getAuthorizerAccessTokenKey() |
||
87 | |||
88 | /** |
||
89 | * Gets the authorizer corp id, or throws if not found. |
||
90 | * |
||
91 | * @throws \EntWeChat\Core\Exception |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getAuthorizerCorpId() |
||
105 | |||
106 | /** |
||
107 | * Sets the authorizer corp id. |
||
108 | * |
||
109 | * @param string $authorizerCorpId |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function setAuthorizerCorpId($authorizerCorpId) |
||
119 | |||
120 | /** |
||
121 | * Gets the authorizer access token. |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getAuthorizerAccessToken() |
||
129 | |||
130 | /** |
||
131 | * Saves the authorizer refresh token in cache. |
||
132 | * |
||
133 | * @param string $permanentCode |
||
134 | * |
||
135 | * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise |
||
136 | */ |
||
137 | public function setAuthorizerPermanentCode($permanentCode) |
||
141 | |||
142 | /** |
||
143 | * Gets the authorizer refresh token cache key. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getAuthorizerPermanentCodeKey() |
||
151 | |||
152 | /** |
||
153 | * Gets the authorizer refresh token. |
||
154 | * |
||
155 | * @throws \EntWeChat\Core\Exception when refresh token is not present |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function getAuthorizerPermanentCode() |
||
169 | |||
170 | /** |
||
171 | * Removes the authorizer access token from cache. |
||
172 | * |
||
173 | * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise. |
||
174 | * Deleting a non-existing entry is considered successful |
||
175 | */ |
||
176 | public function removeAuthorizerAccessToken() |
||
180 | |||
181 | /** |
||
182 | * Removes the authorizer refresh token from cache. |
||
183 | * |
||
184 | * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise. |
||
185 | * Deleting a non-existing entry is considered successful |
||
186 | */ |
||
187 | public function removeAuthorizerPermanentCode() |
||
191 | } |
||
192 |