/** * Use that if you want to authenticate a user via Spredfast OAuth on your site */ session_start(); require_once '../vendor/autoload.php'; $client_id = ''; $client_secret = ''; $redirect_uri = 'https://site.local/oauth_redirect'; /** * Login check. You don't need to set username and password so you could use empty strings for these params */ $auth = new \Spredfast\CustomSolutions\OAuth\Example\ExampleAuth('', '', $client_id, $client_secret, $redirect_uri); $url = $auth->getLoginUrl(); echo '<a href="' . $url . '">login</a>'; // here you should redirect a user // /** * In another script you need to get a code and request an access token */ if (isset($_GET['code'])) { $code = $_GET['code']; $client = new \Spredfast\CustomSolutions\OAuth\Example\ExampleAuth('', '', $client_id, $client_secret, $redirect_uri); try { $access_token = $client->requestAccessToken($code); } catch (\Spredfast\CustomSolutions\OAuth\AuthException $e) { die("Can't get access token"); } } else { die('Code is required'); }