【问题标题】:Trouble with getting User Id through ResouceServer::OwnerId()通过 ResouceServer::OwnerId() 获取用户 ID 的问题
【发布时间】:2015-01-24 18:57:12
【问题描述】:

我已经在 lucadegasperi's github 的 laravel 4 中实现了 Oauth 2。在我的一个控制器中,我尝试使用 ResourceServer::getOwnerId() 检索用户 ID,但我无法这样做。

我的routes.php如下:

Route::post('oauth/access_token', function() {
    return Response::json(Authorizer::issueAccessToken());
});

Route::group(array('before'=>'oauth'), function(){

    Route::post('exp', 'ExpController@store');
});

控制器看起来是这样的(暂时):

class ExpController extends \BaseController {
    public function store() {
           //
           $exp = ResourceServer::getOwnerId();

           return Response::json(
                  array(
                      'message' => $exp
                  ),
                  200 
                )->setCallback(Input::get('callback'));
    }
}

我的日志给了我以下错误:

    production.ERROR: exception 'Symfony\Component\Debug\Exception\
FatalErrorException' with message 'Class 'ResourceServer' not found'

我哪里出错了?我错过了什么吗?

【问题讨论】:

  • 您的控制器在命名空间内吗?如果是,请使用\ResourceServer 或添加use 语句
  • 很抱歉,但我不明白控制器在命名空间中是什么意思...??
  • 在你的控制器(大概是ExpController.php)的顶部有namespace ...;吗?
  • 不...不是全部...我已经复制粘贴了整个控制器...

标签: laravel laravel-4 oauth-2.0


【解决方案1】:

似乎这个包的使用方式发生了一些变化(至少自从我使用它以来)不再有ResourceServer Facade。但是您可以改为调用它:

Authorizer::getResourceOwnerId();

【讨论】:

  • 需要问你这个... Authorizer::getResourceOwnerId() 如果grant_type 是密码,效果很好... 我应该为client_credentials grant_type 使用什么...?因为 Authorizer::getResourceOwnerId() 给了我一条关于 client_credentials 的错误消息....
  • 呸。不知道我脑海中的答案......稍后会看看它。
  • 对不起,我找不到任何东西,也没有时间进一步挖掘。也许问一个关于 SO 的新问题?祝你好运:)
猜你喜欢
  • 1970-01-01
  • 2021-05-01
  • 1970-01-01
  • 2017-05-12
  • 2021-04-09
  • 2021-03-06
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多