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

72 lines 1.9 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\auth\OAuthCrypto;
8 use Leadin\admin\Routing;
9 use Leadin\admin\MenuConstants;
10
11 /**
12 * Class managing OAuth2 authorization
13 */
14 class OAuth {
15
16 /**
17 * Authorizes the plugin with given oauth credentials by storing them in the options DB.
18 *
19 * @param string $refresh_token OAuth refresh token to store.
20 */
21 public static function authorize( $refresh_token ) {
22 $encrypted_refresh_token = OAuthCrypto::encrypt( $refresh_token );
23 Portal_Options::set_refresh_token( $encrypted_refresh_token );
24
25 Portal_Options::set_last_authorize_time();
26 }
27
28 /**
29 * Deauthorizes the plugin by deleting OAuth credentials from the options DB.
30 */
31 public static function deauthorize() {
32 Portal_Options::delete_refresh_token();
33
34 Portal_Options::set_last_deauthorize_time();
35 }
36
37 /**
38 * Attempts to get and decrypt the refresh token.
39 * Records an error if decryption fails or if the token is invalid.
40 *
41 * Note: WordPress sites that are missing keys and salts will have the refresh token stored in plaintext.
42 * The decrypt function will return the plaintext token in this case.
43 *
44 * @return string The result of decrypt function, or an empty string on failure.
45 */
46 public static function get_refresh_token() {
47 $encrypted_refresh_token = Portal_Options::get_refresh_token();
48
49 if ( ! self::is_valid_value( $encrypted_refresh_token ) ) {
50 return '';
51 }
52
53 $refresh_token = OAuthCrypto::decrypt( $encrypted_refresh_token );
54
55 if ( ! self::is_valid_value( $refresh_token ) ) {
56 return false;
57 }
58
59 return $refresh_token;
60 }
61
62 /**
63 * Checks if the provided value is valid (not false, null, or empty).
64 *
65 * @param mixed $value The value to check.
66 * @return bool Whether the value is valid.
67 */
68 private static function is_valid_value( $value ) {
69 return false !== $value && null !== $value && '' !== $value;
70 }
71 }
72