/** * Method to handle redirects from the LaunchKey OAuth service * * '@since 1.0.0 */ public function launchkey_callback() { /** * If the service redirected with an error, * or without an OAuth response code, * or with an invalid OAuth response code, * then redirect to the login page with an error */ if (isset($_GET['error']) || !isset($_GET['code']) || !$this->is_valid_oauth_code($_GET['code'])) { return $this->wp_facade->wp_redirect($this->wp_facade->wp_login_url() . "?launchkey_error=1"); } // Get an access/refresh token for the OAUth code $token_response = $this->get_token_for_code($_GET['code']); // If the response is an error, redirect to the login page with an "SSL" error if ($this->wp_facade->is_wp_error($token_response)) { return $this->wp_facade->wp_redirect($this->wp_facade->wp_login_url() . "?launchkey_ssl_error=1"); } elseif (!$this->is_token_response_valid($token_response)) { return $this->wp_facade->wp_redirect($this->wp_facade->wp_login_url() . "?launchkey_error=1"); } $user_id = $this->get_user_id_by_launchkey_user_hash($token_response['user']); //Log the user in or send them to login form to pair their existing account. if ($user_id) { // If the user is already paired $this->wp_facade->wp_set_auth_cookie($user_id, false); $this->login_user($token_response['access_token'], $token_response['expires_in'], $token_response['refresh_token']); $this->wp_facade->wp_redirect($this->wp_facade->admin_url()); } else { // First Time Pair $this->login_user($token_response['access_token'], $token_response['expires_in'], $token_response['refresh_token']); $this->prepare_for_launchkey_pair($token_response['user'], $token_response['access_token'], $token_response['expires_in'], $token_response['refresh_token']); } }