繁体   English   中英

无法使用Laravel 5.8和Auth0获得身份验证的用户

[英]Unable to get authenticated user using Laravel 5.8 and Auth0

我有一个想使用Auth0保护的Laravel 5.8 API。 到目前为止,我已经遵循了本教程的每个步骤:

  1. 在正面,Login / logout链接当前在Blade中实现,尽管页面上的呈现内容是使用Vue Router完成的,向数据API提出AJAX请求,但这仍然可以正常工作。
  2. Laravel中的默认User模型已被修改为按照教程存储namesubemail ,并且也会填充它。
  3. 使用在教程中创建的jwt中间件来保护API端点,并且我可以在Postman中成功提交GET和硬编码的 Bearer auth令牌,并获得良好的响应。

但是,在某个时候,我希望能够将访问令牌传递给Vue,以便它可以完成其工作,但是我无法获得当前经过身份验证的用户。 击中Auth0后,它使用URL中的auth gobbledlygook重定向回我的回调路由。 该路由反过来加载一个controller方法 ,那里的一切看起来都不错:

// Get the user related to the profile
$auth0User = $this->userRepository->getUserByUserInfo($profile);   // returns good user

if ($auth0User) {
    // If we have a user, we are going to log them in, but if
    // there is an onLogin defined we need to allow the Laravel developer
    // to implement the user as they want an also let them store it.
    if ($service->hasOnLogin()) {                                  // returns false
        $user = $service->callOnLogin($auth0User);
    } else {
        // If not, the user will be fine
        $user = $auth0User;
    }
    \Auth::login($user, $service->rememberUser());     // "normal" Laravel login flow?
}

我不是该框架的专家,但是上面的最后一行似乎开始了“正常”的Laravel用户登录流程。 鉴于此,当我执行auth()->user()甚至app('auth0')->getUser()时,是否应该看到null以外的内容?

如果您是初学者,请尝试使用简单的教程,我建议您这样做

它使用一个简单的JWT包来创建一个jwt令牌,当用户进行身份验证时可以获取该令牌。

JWTAuth::attempt(['email'=>$email,'password'=>$password]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM