public function onRun() { // Initiliase variables $this->page['authenticated'] = false; //============= TODO: put these in theme settings (or component back end settings) =================== // Set the AVC API credentials $clientId = '4320'; $clientSecret = '8ab4693d377cafa884c63203c5b54b89707ffd63'; $redirect = 'http://avc-october.app'; //$redirect = 'http://ampthillveloclub.co.uk/strava'; $response_type = 'code'; $state = 'step1'; // Instatiate Strava API object with AVC client credentials $api = new StravaApi($clientId, $clientSecret); // User has clicked logout (redirects to this page) if (Input::has('logout')) { // Delete Strava session data Session::forget('strava_token'); return Redirect::to('/'); } // Check for Strava session data containing API auth token $session_token = Session::get('strava_token', 'empty'); // We have a Strava auth token in session if (!($session_token == 'empty')) { $api->setAccessToken($session_token); // Set authenticated flag $this->page['authenticated'] = true; // GET - Auth athlete from Strava API $this->page['auth_athlete'] = $api->get('athlete'); //dd($this->page['auth_athlete']); } elseif (Input::has('code') && Input::has('state') && Input::get('state') == 'step1') { // Exchange code for access token for user $result = $api->tokenExchange(Input::get('code')); // Set access token in to the user api object $token = $api->setAccessToken($result->access_token); // Save access token to user's session in cookie Session::put('strava_token', $token); return Redirect::to('/'); //dd($result->athlete); } else { $this->page['url'] = $api->authenticationUrl($redirect, $approvalPrompt = 'auto', $scope = null, $state = 'step1'); } }
public function testIfAuthenticationUrlWithScopeWorksAsExpected() { $expected = 'https://www.strava.com/oauth/authorize' . '?client_id=999' . '&redirect_uri=' . urlencode('https://example.org/') . '&response_type=code' . '&approval_prompt=auto' . '&scope=read'; $url = $this->stravaApi->authenticationUrl('https://example.org/', 'auto', 'read', null); $this->assertEquals($expected, $url); }