处理身份验证OAuth2时出错 [英] Error while processing authentification OAuth2

查看:175
本文介绍了处理身份验证OAuth2时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已遵循此教程从Google获取凭据,但使用了YouTube API范围API之一.

i have follow this tutorial to get credentials from google but for youtube API scope instead of contact API one.

我已经尝试过:

<?php

session_start();

require 'Google/Client.php';
require 'config.php';

//$_SESSION = array();
$client = new Google_Client();
$client->setApplicationName('Test APPS');
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setScopes($scope);
$client->setRedirectUri($redirectUri);
$client->setAccessType($accessType);

if(isset($_GET['code'])){
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location:' . $redirectUri);
}
if(!isset($_SESSION['token'])){
    $url = $client->createAuthUrl();
?>
<a href="<?php echo $url; ?>">Connect</a>
<?php 
}
?>

单击连接"后,我已重定向到google身份验证,并且已将范围进行了授权,但是在url中获取代码时,出现了错误.

after clicking on connect i have been redirected to google authentification and i have autorize scope but when getting code in url i got error with it.

这是错误的回溯

Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect: 'fopen(https://accounts.google.com/o/oauth2/token) [<a href='function.fopen'>function.fopen</a>]: 
failed to open stream: Invalid argument'' in C:\wamp\www\test\Google\IO\Stream.php:112 Stack trace: #0 C:\wamp\www\test\Google\IO\Abstract.php(125): Google_IO_Stream->executeRequest(Object(Google_Http_Request)) 
#1 C:\wamp\www\test\Google\Auth\OAuth2.php(113): Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) 
#2 C:\wamp\www\test\Google\Client.php(135): Google_Auth_OAuth2->authenticate('4/yNyAID-0XYagI...') 
#3 C:\wamp\www\test\index.php(18): Google_Client->authenticate('4/yNyAID-0XYagI...') 
#4 {main} thrown in C:\wamp\www\test\Google\IO\Stream.php on line 112

对根本原因有任何想法吗?

any idea of the root cause?

推荐答案

我刚刚尝试了var_dump(stream_get_wrappers());,但在数组中未找到https.我刚刚取消注释此行extension=php_openssl.dll以启用它,现在可以了.

I have just tried var_dump(stream_get_wrappers()); and i didnt found https in the array. i have just uncomment this line extension=php_openssl.dll to enable it and now it is ok.

感谢达贡的贡献.

这篇关于处理身份验证OAuth2时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆