drcmg28484 2014-05-29 14:02
浏览 62

lucadegasperi / oauth2-server-laravel在filter中访问ResourceServer :: getOwnerId()

I've implemented Lucade Gasperi's oAuth2 server for laravel which can be found here https://github.com/lucadegasperi/oauth2-server-laravel

I am trying to return the user id of the token in the /apps/filters.php but no value is returned. I am using this ResourceServer::getOwnerId().

If I add ResourceServer::getOwnerId() inside /apps/routes.php it will return the user id.

Here is the code

/apps/filters.php

Route::filter('auth_token', function(){
   exit(ResourceServer::getOwnerId());
}); 

Response:

/apps/routes.php

Route::post('test',  array('before' => 'oauth', function(){
    exit(ResourceServer::getOwnerId());
}));

Response: 4

As you can see when I add ResourceServer::getOwnerId() to the Filter it doesn't return the ID.

The filter is working. If I return a random string it will return the string.

Have I missed something? Is it even possible to use ResourceServer::getOwnerId() inside filters.php

Is it because the oauth is getting called after the filter?

  • 写回答

1条回答 默认 最新

  • doushen2154 2014-07-13 00:06
    关注

    The value is being returned just into a different scope. Since filters happen before the route is resolved the data will not carry over. You can store that value in a session variable or put a redirect in the filter and pass it over as a param.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败