/** * @param array $config * * param example: * * private $config = [ * 'app_key' => 'APP KEY', * 'app_secret' => 'APP SECRET', * 'access_token' => 'USER TOKEN' * ]; * */ public function __construct($config) { $serviceFactory = new \OAuth\ServiceFactory(); $serviceFactory->setHttpClient(new CurlClient()); $token = new StdOAuth2Token(); $token->setAccessToken($config['access_token']); $storage = new Session(); $storage->storeAccessToken('linkedin', $token); $redirectUrl = ''; if (isset($_SERVER['HTTP_HOST'])) { $redirectUrl = $_SERVER['HTTP_HOST']; } $credentials = new Credentials($config['app_key'], $config['app_secret'], $redirectUrl); $this->service = $serviceFactory->createService('linkedin', $credentials, $storage, ['r_fullprofile', 'r_emailaddress', 'rw_nus']); }
} //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']); /* * Creates new a read/write Veridu session * More info: https://veridu.com/wiki/SSO_Resource#How_to_do_a_social_single_sign_on */ $api->session->create(false); $veridu_id = $api->sso->createOauth1("twitter", $token->getAccessToken(), $token->getAccessTokenSecret(), $twitter['appid']); //prints veridu_id (User's unique id) print_r($veridu_id);
/** * Initializes the OAuth service * The service is created by \OAuth\ServiceFactory upon service name returned from getServiceName() method * * @return $this */ public function init() { $serviceFactory = new \OAuth\ServiceFactory(); $serviceFactory->setHttpClient(new CurlClient()); $this->service = $serviceFactory->createService($this->getServiceName(), $this->credentials, $this->sessionStorage, $this->scopes); return $this; }