| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Connect\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Utils |
| 11 |
*/ |
| 12 |
class Utils { |
| 13 |
/** |
| 14 |
* get_clients_url |
| 15 |
* @return string |
| 16 |
*/ |
| 17 |
public static function get_clients_url(): string { |
| 18 |
return Config::BASE_URL . '/api/v1/clients'; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* get_redirect_uri |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
public static function get_redirect_uri(): string { |
| 26 |
if ( false !== strpos( Config::ADMIN_PAGE, '?page=' ) ) { |
| 27 |
return admin_url( Config::ADMIN_PAGE ); |
| 28 |
} |
| 29 |
return admin_url( 'options-general.php?page=' . Config::ADMIN_PAGE ); |
| 30 |
} |
| 31 |
|
| 32 |
public static function get_auth_url(): string { |
| 33 |
return Config::BASE_URL . '/v1/oauth2/auth'; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get full authorization URL with all required parameters |
| 38 |
* |
| 39 |
* @param string $client_id |
| 40 |
* |
| 41 |
* @return string |
| 42 |
*/ |
| 43 |
public static function get_authorize_url( string $client_id ): string { |
| 44 |
return add_query_arg( [ |
| 45 |
'client_id' => $client_id, |
| 46 |
'redirect_uri' => rawurlencode( self::get_redirect_uri() ), |
| 47 |
'response_type' => 'code', |
| 48 |
'scope' => Config::SCOPES, |
| 49 |
'state' => wp_create_nonce( Config::STATE_NONCE ), |
| 50 |
], self::get_auth_url() ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* get_deactivation_url |
| 55 |
* @param string $client_id |
| 56 |
* |
| 57 |
* @return string |
| 58 |
*/ |
| 59 |
public static function get_deactivation_url( string $client_id ): string { |
| 60 |
return Config::BASE_URL . "/api/v1/clients/{$client_id}/activation"; |
| 61 |
} |
| 62 |
|
| 63 |
public static function get_jwks_url(): string { |
| 64 |
return Config::BASE_URL . '/v1/.well-known/jwks.json'; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* get_sessions_url |
| 69 |
* @return string |
| 70 |
*/ |
| 71 |
public static function get_sessions_url(): string { |
| 72 |
return Config::BASE_URL . '/api/v1/session'; |
| 73 |
} |
| 74 |
|
| 75 |
public static function get_token_url(): string { |
| 76 |
return Config::BASE_URL . '/api/v1/oauth2/token'; |
| 77 |
} |
| 78 |
} |
| 79 |
|