donglu1973 2014-06-25 15:14 采纳率: 100%
浏览 40
已采纳

Phalconphp OAuth2.0 Wrapper问题

I am trying to get this phalconphp OAuth2.0 wrapper working on my OAuth2.0 server. The README of this repository is not very clear on how to use the namespaces. I have followed the guide but I keep getting the following error :

  Fatal error: Class 'Sum\Oauth2\Server\Storage\Pdo\Mysql\Client' 
not found in C:\localhost\oauth2-phalcon\public\index.php on line 56

Here is my index.php file :

<?php

require __DIR__."/../vendor/autoload.php";

// Setup IIS Rewrite Rules
// Enable the verbs GET,PUT,POST,DELETE
// Check URL Scan for dissallowed seperators eg ; : 

$config = new \Phalcon\Config([
    'database'    => [
        'oauth' => [
            'host'          => 'localhost\test',
            'port'          => 1433,
            'instance'      => 'INSTANCENAME',
            'username'      => 'test',
            'password'      => 'test',
            'dbname'        => 'oauth',                
            'pdoType'       => 'sqlsrv',
            'dialectClass'  => '\Twm\Db\Dialect\Mssql'            
        ],
    ],
    # ...

]);


# Register The Lib to the loader
$loader = new \Phalcon\Loader();

$loader->registerNamespaces([
    "Twm\Db\Adapter\Pdo"            => "../app/library/db/adapter/",
    "Twm\Db\Dialect"                => "../app/library/db/dialect/",
    "League"                        => "../vendor/league/oauth2-server/src/League/OAuth2/Server",    
    //"Sum\Oauth2\Server\Storage\Pdo" => "../Oauth2/Server/Storage/Pdo/Mysql",
    "Sum"                           =>  "../Oauth2/Server/Storage/Pdo/Mysql",
    //"Sum\Oauth2\Server\Storage\Pdo\Mysql" => "../Oauth2/Server/Storage/Pdo/Mysql "
    # ...
])->register();

$app = new \Phalcon\Mvc\Micro();

# set as service
$app->setService('oauth', function() use ($config) {    
    // HERE! We use our custom MSSQL Adapter
   //$oauthdb = new Phalcon\Db\Adapter\Pdo\Mysql($config->database->oauth->toArray());
    $oauthdb = new \Twm\Db\Adapter\Pdo\Mssql($config->database->oauth->toArray());    
    $server = new \League\OAuth2\Server\Authorization(        
        new \Sum\Oauth2\Server\Storage\Pdo\Mysql\Client($oauthdb),
        new Sum\Oauth2\Server\Storage\Pdo\Mysql\Session($oauthdb),
        new Sum\Oauth2\Server\Storage\Pdo\Mysql\Scope($oauthdb)
        // new \Sum\Oauth2\Server\Client($oauthdb),
        //new \Sum\Oauth2\Server\Session($oauthdb),
        //new \Sum\Oauth2\Server\Scope($oauthdb)                            
    );
    # Not required as it called directly from original code
    # $request = new \League\OAuth2\Server\Util\Request();

    # add these 2 lines code if you want to use my own Request otherwise comment it
    $request = new \Sum\Oauth2\Server\Storage\Pdo\Mysql\Request(); 
    $server->setRequest($request);

    $server->setAccessTokenTTL(86400);
    $server->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
});

$app->get('/hello', function() use($world){
   $world = "world";
   echo "hello {$world}:)";   
});

$app->get('/access', function () use ($app) {
    try {
        $params = $app->oauth->getParam(array('client_id', 'client_secret'));
        echo json_encode(
            $app->oauth
                ->getGrantType('client_credentials')
                ->completeFlow($params)
        );
    } catch (\League\OAuth2\Server\Exception\ClientException $e) {
        echo $e->getTraceAsString();
    } catch (\Exception $e) {
        echo $e->getTraceAsString();
    }
});

$app->handle();
//echo $app->handle()->getContent();

The project repository for the phalcon wrapper is here : https://github.com/sumeko/phalcon-oauth2

I have contacted the author already but he is not replying to my emails.

I appreciate any help or advice, thanks.

UPDATE

So I solved my issue. Basically you need to have the standard OAuth2 library installed via composer and the phalconphp OAuth2 wrapper. That solved it :)

  • 写回答

2条回答 默认 最新

  • dongsong1911 2014-06-25 18:50
    关注

    This might be a long shot, but the problem might be with the autoloader that you are explicitly defining. If you use composer's autoload, you don't need to include Sum namespace in Phalcon's loader. Remove all vendor-specific paths from $loader->registerNamespaces() and only use require __DIR__ . "/../vendor/autoload.php" for that.

    Also, it's often more convenient use composer's autoloader for your internal things too, e.g.:

    {
    
        "require": {
            "phpunit/dbunit": "*",
            "phpunit/phpunit": "*",
            "…": "…"
        },
        "autoload": {
            "psr-0": {
                "": "../src"
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵