PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.61
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.61
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / modules / api / class-refresh-token-api-controller.php

class-refresh-token-api-controller.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.61, at public/modules/api/class-refresh-token-api-controller.php

46 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\api;
4
5 use Leadin\api\Base_Api_Controller;
6 use Leadin\auth\OAuth;
7 use Leadin\auth\OAuthCryptoError;
8
9 /**
10 * REST endpoint to retrieve the OAuth refresh token for authenticated users.
11 */
12 class Refresh_Token_Api_Controller extends Base_Api_Controller {
13
14 /**
15 * Class constructor, register route.
16 */
17 public function __construct() {
18 self::register_leadin_route(
19 '/refresh-token',
20 \WP_REST_Server::READABLE,
21 array( $this, 'get_refresh_token' )
22 );
23 }
24
25 /**
26 * Callback for refresh token endpoint.
27 * leadin/v1/refresh-token Method:GET.
28 *
29 * @return WP_REST_Response The refresh token or an error response.
30 */
31 public function get_refresh_token() {
32 $refresh_token = OAuth::get_refresh_token();
33
34 if ( false === $refresh_token ) {
35 return new \WP_REST_Response( array( 'error' => OAuthCryptoError::DECRYPT_FAILED ), 500 );
36 }
37
38 if ( empty( $refresh_token ) ) {
39 return new \WP_REST_Response( array( 'error' => 'not_connected' ), 403 );
40 }
41
42 return new \WP_REST_Response( array( 'refreshToken' => $refresh_token ), 200 );
43 }
44
45 }
46