duancoubeng5909 2013-09-24 08:45
浏览 264
已采纳

“redirect_uri”无法使用OAuth2客户端

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 ?

  • 写回答

1条回答 默认 最新

  • dpspn60064 2013-09-24 10:05
    关注

    Have you given the same redirect uri in your application settings page? If you specify about your application (type of application like facebook, twitter etc.,) I can help you in better way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog