| | |
| | | |
| | | trait OAuth |
| | | { |
| | | use _Base, Admin; |
| | | use _Base, Admin, ServiceMap; |
| | | protected OAuthURLs $oauth; |
| | | /** |
| | | * Child classes must set this (e.g. 'https://api.example.com/v1/') |
| | |
| | | { |
| | | return $this->getRequestHeaders(); |
| | | } |
| | | public function getOAuthBaseURL():?string |
| | | { |
| | | return $this->baseOAuthUrl; |
| | | } |
| | | |
| | | /** |
| | | * Default to the base handleResponse method, but extensions can modify accordingly |
| | |
| | | } |
| | | |
| | | // Get integration instance |
| | | $integration = JVB()->connect($this->service_name, $user_id); |
| | | $integration = $this->getService($this->service_name); |
| | | |
| | | if (!$integration) { |
| | | if (!$integration || !method_exists($integration, 'switchUser')) { |
| | | wp_die('Invalid service: ' . esc_html($this->service_name), 'OAuth Error'); |
| | | } |
| | | |
| | | $integration->switchUser($user_id); |
| | | |
| | | |
| | | // Exchange code for tokens |
| | | $result = $integration->handleOAuthCode($code, $state); |