【发布时间】:2016-03-14 02:38:45
【问题描述】:
我已经按照这个优秀的教程Building a Web App with Lumen and OAuth2 来设置 OAuth2 和 Lumen。除了现在一切正常之外,我想访问当前经过身份验证的用户信息/模型。
我的路由在我登录后正确发布了提供的信息,我可以在控制器内与 Netbeans 中断,但我不清楚如何从底层 Auth 框架获取用户。我尝试了Authentication - Laravel 此处指出的三种方法,但无济于事。流明日志显示:
==== routes.php ====
$app->group(['namespace' => 'App\Http\Controllers','prefix' => 'api', 'middleware' => 'oauth'], function($app)
{
$app->post('info', 'InfoController@send');
}
==== InfoController.php ====
namespace App\Http\Controllers;
// the controllers
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Authenticatable;
class InfoController extends Controller{
/* /api/info methods */
public function send(Request $request){
// can iterate over the entire users table but I just
// want the current user (must be some method through
// the authentication stack)
$users = \App\Auth\User::all();
foreach ($users as $user) {
$name = $user->name;
$key = $user->getAuthIdentifier();
$pwd = $user->getAuthPassword();
}
// CODE GETS HERE BUT how to get the current user?
// Authenticated OK (request supplies "Access-Token: Bearer ...")
}
}
【问题讨论】:
标签: authentication oauth oauth-2.0 lumen