| @@ -175,16 +175,14 @@ | ||
| 175 | 175 | * @return string |
| 176 | 176 | * Returns TRUE after setting the options. |
| 177 | 177 | */ |
| 178 | 178 | public static function login(array $params) { |
| 179 | - $parts = explode('.', $params['token']); | |
| 180 | - $token_data = json_decode(WebTotem::base64UrlDecode($parts[1]), true); | |
| 181 | - $token_expired = $token_data['exp'] - 60; | |
| 179 | + $token_expired = time() + $params['token']['expiresIn'] - 60; | |
| 182 | 180 | |
| 183 | 181 | self::setOptions([ |
| 184 | 182 | 'activated' => TRUE, |
| 185 | 183 | 'auth_token_expired' => $token_expired, |
| 186 | - 'auth_token' => $params['token'], | |
| 184 | + 'auth_token' => $params['token']['value'], | |
| 187 | 185 | 'api_key' => $params['api_key'], |
| 188 | 186 | 'multisite_options' => WebTotem::isMultiSite() |
| 189 | 187 | ]); |
| 190 | 188 | |
| @@ -190,31 +188,9 @@ | ||
| 190 | 188 | |
| 191 | 189 | return TRUE; |
| 192 | 190 | } |
| 193 | 191 | |
| 194 | - /** | |
| 195 | - * Save authentication token and token expiration dates in settings. | |
| 196 | - * | |
| 197 | - * @param string $token | |
| 198 | - * Parameters for authorization. | |
| 199 | - * | |
| 200 | - * @return bool | |
| 201 | - * Returns TRUE after setting the options. | |
| 202 | - */ | |
| 203 | - public static function refreshToken(string $token) { | |
| 204 | - $parts = explode('.', $token); | |
| 205 | - $token_data = json_decode(WebTotem::base64UrlDecode($parts[1]), true); | |
| 206 | - $token_expired = $token_data['exp'] - 60; | |
| 207 | - | |
| 208 | - self::setOptions([ | |
| 209 | - 'auth_token_expired' => $token_expired, | |
| 210 | - 'auth_token' => $token, | |
| 211 | - ]); | |
| 212 | - | |
| 213 | - return TRUE; | |
| 214 | - } | |
| 215 | - | |
| 216 | - /** | |
| 192 | + /** | |
| 217 | 193 | * Checks whether the user has activated the plugin using the API key. |
| 218 | 194 | * |
| 219 | 195 | * @return bool |
| 220 | 196 | * Returns the module activation status. |
| @@ -242,33 +218,8 @@ | ||
| 242 | 218 | ]); |
| 243 | 219 | return TRUE; |
| 244 | 220 | } |
| 245 | 221 | |
| 246 | - /** | |
| 247 | - * Return the current API access token, authorizing only when necessary. | |
| 248 | - * | |
| 249 | - * The token is reused until it actually expires; a new sign-in happens only | |
| 250 | - * when there is no token or the stored one is past its expiry. | |
| 251 | - * | |
| 252 | - * @return string | |
| 253 | - * Access token, or an empty string when authorization failed. | |
| 254 | - */ | |
| 255 | - public static function getAuthToken() { | |
| 256 | - $token = self::getOption('auth_token'); | |
| 257 | - $expired_at = (int) self::getOption('auth_token_expired'); | |
| 258 | - | |
| 259 | - if ($token && $expired_at > time()) { | |
| 260 | - return $token; | |
| 261 | - } | |
| 262 | - | |
| 263 | - $api_key = self::getOption('api_key'); | |
| 264 | - if ($api_key && WebTotemAPI::auth($api_key) === 'success') { | |
| 265 | - return self::getOption('auth_token'); | |
| 266 | - } | |
| 267 | - | |
| 268 | - return $token ?: ''; | |
| 269 | - } | |
| 270 | - | |
| 271 | 222 | /** |
| 272 | 223 | * Set notification. |
| 273 | 224 | * |
| 274 | 225 | * @param string $type |
| @@ -413,14 +364,12 @@ | ||
| 413 | 364 | * @return void |
| 414 | 365 | */ |
| 415 | 366 | public static function clearAllHosts() { |
| 416 | 367 | |
| 417 | - $hosts = WebTotemAPI::getSites(1, 1000000); | |
| 418 | - foreach ($hosts as $site) { | |
| 419 | - if (empty($site['name'])) { | |
| 420 | - continue; | |
| 421 | - } | |
| 422 | - $blog_id = self::getBlogId($site['name']); | |
| 368 | + $data = WebTotemAPI::getSites(); | |
| 369 | + foreach ($data['edges'] as $site) { | |
| 370 | + $site = $site['node']; | |
| 371 | + $blog_id = self::getBlogId($site['hostname']); | |
| 423 | 372 | delete_blog_option($blog_id, 'wtotem_host_id'); |
| 424 | 373 | delete_blog_option($blog_id, 'wtotem_host_name'); |
| 425 | 374 | } |
| 426 | 375 | |