“redirect_uri”无法使用OAuth2客户端

时间:2013-09-24 08:45:42

标签: php symfony oauth-2.0 client

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;
    }
}

这是我的代码,使用oauth2连接到其他应用程序以获取access_token,以便使用它连接到API。

但问题是,在进行身份验证后,我没有重定向到我的应用程序(“http://localhost/myappli/web/app_dev.php/”)。

那么如何将其重定向到我的应用程序以获取access_token

1 个答案:

答案 0 :(得分:1)

您是否在应用程序设置页面中提供了相同的重定向uri?如果您指定了您的应用程序(Facebook,Twitter等应用程序的类型),我可以更好地帮助您。

相关问题