/** * Creates URI factory for building urls * Setups session storage * * @param DiInterface $di * @param TokenStorageInterface $sessionStorage */ public function __construct(DiInterface $di, TokenStorageInterface $sessionStorage) { $this->setDI($di); $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $this->currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $this->currentUri->setQuery(''); $this->sessionStorage = $sessionStorage; }
public function getAuthService($site, $landingPage) { $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); $serviceFactory = new \OAuth\ServiceFactory(); $credentials = new Credentials($this->siteCredentials[$site]['key'], $this->siteCredentials[$site]['secret'], $landingPage); $storage = new Session(); $service = $serviceFactory->createService($site, $credentials, $storage, array('userinfo_email', 'userinfo_profile')); return $service; }
public function __construct($consumer_key, $consumer_secret, $callbackUrl = null, \OAuth\Common\Storage\TokenStorageInterface $storageAdapter = null) { if ($callbackUrl == null) { $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); $callbackUrl = $currentUri->getAbsoluteUri(); } $factory = new \OAuth\ServiceFactory(); $credentials = new \OAuth\Common\Consumer\Credentials($consumer_key, $consumer_secret, $callbackUrl); if ($storageAdapter == null) { $storageAdapter = new \OAuth\Common\Storage\Session(); } $this->service = $factory->createService('google', $credentials, $storageAdapter, ['fitness_activity_read']); }
public function loginFacebook() { /** * Bootstrap the example * *require_once __DIR__ . '/bootstrap.php'; */ $storage = new Session(); // Session storage $servicesCredentials['facebook']['key'] = '641605372625410'; $servicesCredentials['facebook']['secret'] = 'ddcc4fda61288b868a6ab30eae14400c'; // Setup the credentials for the requests $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setHost($_SERVER['HTTP_HOST']); $currentUri->setQuery(''); $credentials = new Credentials($servicesCredentials['facebook']['key'], $servicesCredentials['facebook']['secret'], $currentUri->getAbsoluteUri()); // Instantiate the Facebook service using the credentials, http client and storage mechanism for the token /** @var $facebookService Facebook */ $serviceFactory = new \OAuth\ServiceFactory(); $facebookService = $serviceFactory->createService('facebook', $credentials, $storage, array()); if (!empty($_GET['code'])) { // This was a callback request from facebook, get the token $token = $facebookService->requestAccessToken($_GET['code']); // Send a request with it $result = json_decode($facebookService->request('/me'), true); // Show some of the resultant data echo 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name']; $user = User::register($result); } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { $url = $facebookService->getAuthorizationUri(); header('Location: ' . $url); } else { $url = $currentUri->getRelativeUri() . '?go=go'; echo "<a href='{$url}'>Login with Facebook!</a>"; } }
/** * Create connector * @param $name the unique connector name * @param $service array the service * @param $storage_type String the storage type * @return connector instance */ public function createConnector($name, $service, $session, $storage_type) { if (array_key_exists("callback_url", $service) && $service['callback_url'] != "") { $callback_url = $service['callback_url']; } else { $callback_url = $this->router->generate("oauthexternal_connect", array("connectorName" => $name), true); } //handle special redirect callback for some services (have to be defined on the service website) if ($service['type'] == "twitter") { $callback_url = "oob"; } //handle version of oauth by service type $version = 2; if (strtolower($service['type']) == "bitbucket" || strtolower($service['type']) == "etsy" || strtolower($service['type']) == "fitbit" || strtolower($service['type']) == "tumblr" || strtolower($service['type']) == "twitter") { $version = 1; } $connector = new ConnectorWrapper($name, null, $service['type'], $callback_url, $service['scopes'], $version); // Setup the storage if ($storage_type == "session") { $storage = new SymfonySession($session); } else { //memory $storage = new Memory(); } $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); // Setup the credentials $credentials = new Credentials($service["client_id"], $service["client_secret"], "oob"); //$currentUri->getAbsoluteUri() $serviceFactory = new \OAuth\ServiceFactory(); //$serviceFactory->setHttpClient(new CurlClient()); $client = $serviceFactory->createService($service["type"], $credentials, $storage); $connector->setService($client); return $connector; }
/** * Returns the cached current_uri object or creates and caches it if it is * not already created. In each case the query string is updated based on * the $query parameter. * * @param string $service_name The name of the service * @param string $query The query string of the current_uri * used in redirects * @return \OAuth\Common\Http\Uri\UriInterface */ protected function get_current_uri($service_name, $query) { if ($this->current_uri) { $this->current_uri->setQuery($query); return $this->current_uri; } $uri_factory = new \OAuth\Common\Http\Uri\UriFactory(); $super_globals = $this->request->get_super_global(\phpbb\request\request_interface::SERVER); if (!empty($super_globals['HTTP_X_FORWARDED_PROTO']) && $super_globals['HTTP_X_FORWARDED_PROTO'] === 'https') { $super_globals['HTTPS'] = 'on'; $super_globals['SERVER_PORT'] = 443; } $current_uri = $uri_factory->createFromSuperGlobalArray($super_globals); $current_uri->setQuery($query); $this->current_uri = $current_uri; return $current_uri; }
require_once __DIR__ . '/../vendor/autoload.php'; if (!is_file(__DIR__ . '/../../settings.php')) { die('Please copy ../../settings.php.dist to ../../settings.php'); } //requiring client configuration require_once __DIR__ . '/../../settings.php'; if (!is_file(__DIR__ . '/twitter-settings.php')) { die('Please copy twitter-settings.php.dist to twitter-settings.php'); } //requiring social app configuration require_once __DIR__ . '/twitter-settings.php'; // token storage $storage = new OAuth\Common\Storage\Session(); // current uri $uriFactory = new OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); // Setup the credentials for the requests $credentials = new OAuth\Common\Consumer\Credentials($twitter['key'], $twitter['secret'], $currentUri->getAbsoluteUri()); // Instantiate the Twitter service using the credentials, http client and storage mechanism for the token $serviceFactory = new OAuth\ServiceFactory(); $client = new OAuth\Common\Http\Client\CurlClient(); $client->setCurlParameters(array(CURLOPT_ENCODING => '')); $serviceFactory->setHttpClient($client); $twitterService = $serviceFactory->createService('twitter', $credentials, $storage); if (!empty($_GET['oauth_token'])) { $twitterToken = $storage->retrieveAccessToken('Twitter'); // This was a callback request from twitter, get the token $token = $twitterService->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier'], $twitterToken->getRequestTokenSecret()); //Instantiates the API object $api = Veridu\API::factory($veridu['client'], $veridu['secret'], $veridu['version']);
/** * Returns the cached current_uri object or creates and caches it if it is * not already created. In each case the query string is updated based on * the $query parameter. * * @param string $service_name The name of the service * @param string $query The query string of the current_uri * used in redirects * @return \OAuth\Common\Http\Uri\UriInterface */ protected function get_current_uri($service_name, $query) { if ($this->current_uri) { $this->current_uri->setQuery($query); return $this->current_uri; } $uri_factory = new \OAuth\Common\Http\Uri\UriFactory(); $current_uri = $uri_factory->createFromSuperGlobalArray($this->request->get_super_global(\phpbb\request\request_interface::SERVER)); $current_uri->setQuery($query); $this->current_uri = $current_uri; return $current_uri; }
/** * Callback for Linkedin. * * @deprecated */ public function callbackLoginLinkedinAction() { $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); $config = $this->getServiceLocator()->get('Config'); // Session storage $storage = new Session(); // Setup the credentials for the requests $credentials = new Credentials($config['linkedin']['appId'], $config['linkedin']['secret'], $currentUri->getAbsoluteUri()); $serviceFactory = new \OAuth\ServiceFactory(); // Instantiate the Linkedin service using the credentials, http client and storage mechanism for the token /** @var $linkedinService Linkedin */ $linkedinService = $serviceFactory->createService('linkedin', $credentials, $storage, array('r_basicprofile')); if (!empty($_GET['code'])) { // retrieve the CSRF state parameter $state = isset($_GET['state']) ? $_GET['state'] : null; // This was a callback request from linkedin, get the token $token = $linkedinService->requestAccessToken($_GET['code'], $state); // Send a request with it. Please note that XML is the default format. $result = json_decode($linkedinService->request('/people/~?format=json'), true); // Show some of the resultant data echo 'Your linkedin first name is ' . $result['firstName'] . ' and your last name is ' . $result['lastName']; } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { $url = $linkedinService->getAuthorizationUri(); header('Location: ' . $url); exit; } else { $url = $currentUri->getRelativeUri() . '?go=go'; echo "<a href='{$url}'>Login with Linkedin!</a>"; } }