PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.7
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.7
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 / auth / class-oauth.php

class-oauth.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.7, at public/auth/class-oauth.php

64 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\auth;
4
5 use Leadin\data\User;
6 use Leadin\data\Portal_Options;
7 use Leadin\client\Access_Token_Api_Client;
8 use Leadin\auth\OAuthCrypto;
9 use Leadin\admin\Routing;
10 use Leadin\admin\MenuConstants;
11
12 /**
13 * Class managing OAuth2 authorization
14 */
15 class OAuth {
16
17 /**
18 * Return the flag checking if we're connected with OAuth.
19 *
20 * @return bool True if the OAuth version of the plugin is enabled or not.
21 */
22 public static function is_enabled() {
23 return ! empty( Portal_Options::get_refresh_token() );
24 }
25
26 /**
27 * Authorizes the plugin with given oauth credentials by storing them in the options DB.
28 *
29 * @param string $refresh_token OAuth refresh token to store.
30 */
31 public static function authorize( $refresh_token ) {
32 $encrypted_refresh_token = OAuthCrypto::encrypt( $refresh_token );
33 Portal_Options::set_refresh_token( $encrypted_refresh_token );
34 }
35
36 /**
37 * Deauthorizes the plugin by deleting OAuth credentials from the options DB.
38 */
39 public static function deauthorize() {
40 Portal_Options::delete_access_token();
41 Portal_Options::delete_refresh_token();
42 Portal_Options::delete_expiry_time();
43 }
44
45 /**
46 * Returns the refresh token stored in the options table.
47 *
48 * @return string The stored refresh token in the Options table.
49 *
50 * @throws \Exception If no refresh token is available.
51 */
52 public static function get_refresh_token() {
53 $encrypted_refresh_token = Portal_Options::get_refresh_token();
54
55 if ( '' === $encrypted_refresh_token ) {
56 self::deauthorize();
57 throw new \Exception( 'Refresh token is empty' );
58 }
59
60 return OAuthCrypto::decrypt( $encrypted_refresh_token );
61 }
62
63 }
64