【发布时间】:2014-05-16 14:48:03
【问题描述】:
您好,有点问题,我找不到任何线索,就这样
我正在使用来自 here 的 OAuth2-client,并且正在使用 codeigniter
这是我的控制器:
public function index()
{
include(APPPATH.'libraries/League/OAuth2/Client/Provider/IdentityProvider.php');
include(APPPATH.'libraries/League/OAuth2/Client/Provider/Google.php');
$provider = new League\OAuth2\Client\Provider\Google(array(
'clientId' => '********************.apps.googleusercontent.com',
'clientSecret' => '**************************',
'redirectUri' => '**************************/oauth2callback'
));
if ( ! isset($_GET['code'])) {
// If we don't have an authorization code then get one
$provider->authorize();
} else {
try {
// Try to get an access token (using the authorization code grant)
$t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code']));
// NOTE: If you are using Eventbrite you will need to add the grant_type parameter (see below)
// $t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code'], 'grant_type' => 'authorization_code'));
try {
// We got an access token, let's now get the user's details
$userDetails = $provider->getUserDetails($t);
foreach ($userDetails as $attribute => $value) {
var_dump($attribute, $value) . PHP_EOL . PHP_EOL;
}
} catch (Exception $e) {
// Failed to get user details
}
} catch (Exception $e) {
// Failed to get access token
}
}
}
我获得了 OAuth 类并将其保存到我的库文件夹中
不知何故,我设法打开了谷歌“选择帐户”或“登录”以及的权限请求
但是当我点击接受时,页面会重新加载到这个 url https://mysite.com/oauth2callback?state=****&code=***
最后是 404。
有没有人有更好的解决方案,谁能帮助我。 这是我第一次尝试使用 OAUTH 并在谷歌应用程序引擎中工作,所以请放过我。提前致谢。
【问题讨论】:
-
您的应用是否配置为响应对mysite.com/oauth2callback的 GET 请求
-
@GwynHowell 不,我只有那个代码,也许这就是我得到 404 的原因,不知道如何回应......
-
我会回复的
-
@GwynHowell 谢谢,我会试试的。
标签: php codeigniter google-app-engine oauth oauth-2.0