const CLIENT_ID = '....';
const CLIENT_SECRET = '';
const REDIRECT_URI = 'http://localhost/myappli/web/app_dev.php/';
const AUTHORIZATION_ENDPOINT = 'http://example.com/';
const TOKEN_ENDPOINT = 'http://example/index.php5/oauth/access_token';
/**
* Connexion to API
*
* @return response
*/
public function connexionAction()
{
$client = new Client(self::CLIENT_ID, self::CLIENT_SECRET);
if (!isset($_GET['code']))
{
$authUrl = $client->getAuthenticationUrl(self::AUTHORIZATION_ENDPOINT, self::REDIRECT_URI);
return $this->redirect($authUrl);
}
else
{
$params = array('code' => $_GET['code'], 'redirect_uri' => self::REDIRECT_URI);
$infosConnexion = $client->getAccessToken(self::TOKEN_ENDPOINT, 'authorization_code', $params);
$accessToken = $infosConnexion['result']['access_token'];
$client->setAccessToken($accessToken);
$response = $client->fetch('http://example/index.php5/api/v3/user/infos');
//var_dump($response);exit;
}
}
This is my code to connect to an other application using oauth2 to get access_token
in order to using it to connect then to an API.
But the issue is that after authenticating I am not redirected to my application ("http://localhost/myappli/web/app_dev.php/
").
So how it is possible to be redirected to my application to get the access_token
?