我正在尝试使用oauth2-client中的oauth2-client。
我通过composer安装了软件包,它在我的root中创建了一个供应商文件夹,其中包含了联盟包。 然后我将其复制到我的application / third_party / vendor文件夹中。
在我的控制器中,我试图这样做:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class APl extends MY_Controller
{
public function __construct()
{
parent::__construct();
// Force SSL
$this->force_ssl();
// Form and URL helpers always loaded (just for convenience)
$this->load->helper('url');
$this->load->helper('form');
//Load Libraries
$this->load->library('managers/NameManager');
$this->load->library('managers/BreadcrumbManager');
}
public function aPLogin() {
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'demoapp', // The client ID assigned to you by the provider
'clientSecret' => 'demopass', // The client password assigned to you by the provider
'redirectUri' => 'http://example.com/your-redirect-url/',
'urlAuthorize' => 'http://brentertainment.com/oauth2/lockdin/authorize',
'urlAccessToken' => 'http://brentertainment.com/oauth2/lockdin/token',
'urlResourceOwnerDetails' => 'http://brentertainment.com/oauth2/lockdin/resource'
]);
}
}
在我的配置文件中,我尝试使用此代码:
$config['composer_autoload'] = TRUE;
require FCPATH . 'third_party\vendor\autoload.php';
在我的index.php文件中如下所示:
require FCPATH . 'third_party\vendor\autoload.php';
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*/
require_once BASEPATH.'core/CodeIgniter.php';
我尝试通过以下方式更改FCPATH:
require_once APPPATH.'third_party\vendor\autoload.php';
也尝试过:
include_once BASEPATH.'../application/third_party/vendor/autoload.php';
然后我要么:
Fatal error: require(): Failed opening required 'D:\wamp\www\codeigniter\third_party\vendor\autoload.php' (include_path='.;C:\php\pear') in D:\wamp\www\codeigniter\index.php on line 311
或
Message: Class 'League\OAuth2\Client\Provider\GenericProvider' not found
答案 0 :(得分:2)
我只想告诉你我使用你想要使用的软件包需要什么。我设置了CodeIgniter的全新安装,然后执行以下操作......
首先,我在config / config中设置了composer autoloading:
$config['composer_autoload'] = TRUE;
接下来,最小的composer.json,位于APPPATH:
{
"minimum-stability": "dev",
"require": {
"league/oauth2-client": "2.2.1"
}
}
从命令行:
cd /path/to/application
composer install
然后,在我的欢迎控制器中,我把它放在:
public function oauth_test()
{
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'demoapp', // The client ID assigned to you by the provider
'clientSecret' => 'demopass', // The client password assigned to you by the provider
'redirectUri' => 'http://example.com/your-redirect-url/',
'urlAuthorize' => 'http://brentertainment.com/oauth2/lockdin/authorize',
'urlAccessToken' => 'http://brentertainment.com/oauth2/lockdin/token',
'urlResourceOwnerDetails' => 'http://brentertainment.com/oauth2/lockdin/resource'
]);
echo '<pre>';
var_dump( $provider );
echo '</pre>';
}
当我在浏览器中访问/ welcome / oauth_test时,我明白了这一点:
object(League\OAuth2\Client\Provider\GenericProvider)#15 (17) {
["urlAuthorize":"League\OAuth2\Client\Provider\GenericProvider":private]=>
string(51) "http://brentertainment.com/oauth2/lockdin/authorize"
["urlAccessToken":"League\OAuth2\Client\Provider\GenericProvider":private]=>
string(47) "http://brentertainment.com/oauth2/lockdin/token"
["urlResourceOwnerDetails":"League\OAuth2\Client\Provider\GenericProvider":private]=>
string(50) "http://brentertainment.com/oauth2/lockdin/resource"
["accessTokenMethod":"League\OAuth2\Client\Provider\GenericProvider":private]=>
NULL
["accessTokenResourceOwnerId":"League\OAuth2\Client\Provider\GenericProvider":private]=>
NULL
["scopes":"League\OAuth2\Client\Provider\GenericProvider":private]=>
NULL
["scopeSeparator":"League\OAuth2\Client\Provider\GenericProvider":private]=>
NULL
["responseError":"League\OAuth2\Client\Provider\GenericProvider":private]=>
string(5) "error"
["responseCode":"League\OAuth2\Client\Provider\GenericProvider":private]=>
NULL
["responseResourceOwnerId":"League\OAuth2\Client\Provider\GenericProvider":private]=>
string(2) "id"
["clientId":protected]=>
string(7) "demoapp"
["clientSecret":protected]=>
string(8) "demopass"
["redirectUri":protected]=>
string(37) "http://example.com/your-redirect-url/"
["state":protected]=>
NULL
["grantFactory":protected]=>
object(League\OAuth2\Client\Grant\GrantFactory)#16 (1) {
["registry":protected]=>
array(0) {
}
}
["requestFactory":protected]=>
object(League\OAuth2\Client\Tool\RequestFactory)#17 (0) {
}
["httpClient":protected]=>
object(GuzzleHttp\Client)#18 (1) {
["config":"GuzzleHttp\Client":private]=>
array(7) {
["handler"]=>
object(GuzzleHttp\HandlerStack)#19 (3) {
["handler":"GuzzleHttp\HandlerStack":private]=>
object(Closure)#26 (2) {
["static"]=>
array(2) {
["default"]=>
object(Closure)#24 (2) {
["static"]=>
array(2) {
["default"]=>
object(GuzzleHttp\Handler\CurlMultiHandler)#20 (5) {
["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
object(GuzzleHttp\Handler\CurlFactory)#21 (2) {
["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
array(0) {
}
["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
int(50)
}
["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
int(1)
["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
NULL
["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
array(0) {
}
["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
array(0) {
}
}
["sync"]=>
object(GuzzleHttp\Handler\CurlHandler)#22 (1) {
["factory":"GuzzleHttp\Handler\CurlHandler":private]=>
object(GuzzleHttp\Handler\CurlFactory)#23 (2) {
["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
array(0) {
}
["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
int(3)
}
}
}
["parameter"]=>
array(2) {
["$request"]=>
string(10) ""
["$options"]=>
string(10) ""
}
}
["streaming"]=>
object(GuzzleHttp\Handler\StreamHandler)#25 (1) {
["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=>
array(0) {
}
}
}
["parameter"]=>
array(2) {
["$request"]=>
string(10) ""
["$options"]=>
string(10) ""
}
}
["stack":"GuzzleHttp\HandlerStack":private]=>
array(4) {
[0]=>
array(2) {
[0]=>
object(Closure)#27 (1) {
["parameter"]=>
array(1) {
["$handler"]=>
string(10) ""
}
}
[1]=>
string(11) "http_errors"
}
[1]=>
array(2) {
[0]=>
object(Closure)#28 (1) {
["parameter"]=>
array(1) {
["$handler"]=>
string(10) ""
}
}
[1]=>
string(15) "allow_redirects"
}
[2]=>
array(2) {
[0]=>
object(Closure)#29 (1) {
["parameter"]=>
array(1) {
["$handler"]=>
string(10) ""
}
}
[1]=>
string(7) "cookies"
}
[3]=>
array(2) {
[0]=>
object(Closure)#30 (1) {
["parameter"]=>
array(1) {
["$handler"]=>
string(10) ""
}
}
[1]=>
string(12) "prepare_body"
}
}
["cached":"GuzzleHttp\HandlerStack":private]=>
NULL
}
["allow_redirects"]=>
array(5) {
["max"]=>
int(5)
["protocols"]=>
array(2) {
[0]=>
string(4) "http"
[1]=>
string(5) "https"
}
["strict"]=>
bool(false)
["referer"]=>
bool(false)
["track_redirects"]=>
bool(false)
}
["http_errors"]=>
bool(true)
["decode_content"]=>
bool(true)
["verify"]=>
bool(true)
["cookies"]=>
bool(false)
["headers"]=>
array(1) {
["User-Agent"]=>
string(56) "GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.0.22-0ubuntu0.16.04.1"
}
}
}
}
所以,除此之外你所做的任何事情都是不必要的。如果是我,我想我会尝试删除整个供应商目录并再试一次。此外,我注意到你在Windows上,虽然我认为这不重要,但我在Linux上(这是大多数网络代码的生产环境)。