/** * Retrieve the name from a service instance. * * @param ServiceInterface $oauthService * * @return string */ public static function getServiceName(ServiceInterface $oauthService) { if ($oauthService instanceof AbstractService) { return $oauthService->service(); } return preg_replace('/^.*\\\\/', '', get_class($oauthService)); }
/** * @param array $config * @param ServiceInterface $service * @param array $options * @param $id */ public function __construct(array $config, ServiceInterface $service, array $options, $id) { $this->config = $config; $this->service = $service; $this->options = $options; $this->id = $id; static::$provider = $service->service(); }
public function __construct(ServiceInterface $service) { try { $response = $service->request($this->userEndpoint); } catch (\OAuth\Common\Storage\Exception\TokenNotFoundException $e) { throw $e; } catch (\OAuth\Common\Http\Exception\TokenResponseException $e) { throw $e; } catch (\OAuth\Common\Token\Exception\ExpiredTokenException $e) { throw $e; } $object = $this->decodeResponse($response); $this->user = $this->getUserResponse($object); }
/** * Twitter connect */ public function connectTwitter() { if (!empty($_GET['oauth_token'])) { $token = $this->session->retrieveAccessToken('Twitter'); // This was a callback request from twitter, get the token $this->service->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier'], $token->getRequestTokenSecret()); // Send a request now that we have access token $result = json_decode($this->service->request('account/verify_credentials.json'), true); return $result; } elseif (isset($_GET['denied'])) { $denied = $_GET['denied']; return compact('denied'); } else { // extra request needed for oauth1 to request a request token :-) $token = $this->service->requestRequestToken(); $url = $this->service->getAuthorizationUri(array('oauth_token' => $token->getRequestToken())); header('Location: ' . $url); } }
/** * Redirect to the authorization page for the service * * @param string $provider The name of the service * @param string|null $callbackUrl The URL to be used for the credentials * @param array|null $scope The scope of the access (OAuth2 only) * @return \Illuminate\Http\RedirectResponse */ public function authorizationRedirect($provider, $callbackUrl = null, array $scope = null) { $this->service = $this->provider($provider, $callbackUrl, $scope); if (is_a($this->service, '\\OAuth\\OAuth1\\Service\\AbstractService')) { $token = $this->service->requestRequestToken(); $url = $this->service->getAuthorizationUri(array('oauth_token' => $token->getRequestToken())); } elseif (is_a($this->service, '\\OAuth\\OAuth2\\Service\\AbstractService')) { $url = $this->service->getAuthorizationUri(); } return Redirect::to((string) $url); }
/** * {@inheritdoc} */ public function getImageRawData($width = false, $height = false) { if (!$this->supportsImageUrl()) { throw new Exception('Image url is not supported by "' . basename(get_class($this)) . '" class!'); } if (!$this->getImageUrl()) { throw new Exception('Image url is empty'); } $rawImage = $this->service->httpRequest($this->getImageUrl(), [], [], 'GET'); $image = Image::fromData($rawImage); if ($width or $height) { /** @noinspection PhpUndefinedMethodInspection */ $image->resize($width ? $width : null, $height ? $height : null); } try { return $image->get(); } catch (\Exception $e) { throw new Exception('Exception occurred during saving image: ' . $e->getMessage(), $e->getCode(), $e); } }
/** * Returns the access token API endpoint. * * @return UriInterface */ public function getAccessTokenEndpoint() { return $this->provider->getAccessTokenEndpoint(); }
/** * Sends an authenticated API request to the path provided. * If the path provided is not an absolute URI, the base API Uri (service-specific) will be used. * * @param string|UriInterface $path * @param string $method HTTP method * @param array $body Request body if applicable (an associative array will * automatically be converted into a urlencoded body) * @param array $extraHeaders Extra headers if applicable. These will override service-specific * any defaults. * * @return array Decoded response */ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array()) { $this->assertServiceInstance(); $response = $this->service->request($path, $method, $body, $extraHeaders); return json_decode($response, true); }
/** * @return mixed */ public function getUserData() { $result = json_decode($this->service->request('/people/~?format=json'), true); return $result; }
/** * @return string */ public function getAuthorizationUri() : string { $url = $this->service->getAuthorizationUri(); return $url->__toString(); }