【发布时间】:2017-06-12 20:10:31
【问题描述】:
我的应用程序是一个单页应用程序,在客户端使用 Angular 1.x,在我的服务器/api 使用 Laravel 5.3。我很容易设法使 Auth0 身份验证在我的客户端(角度)上工作,并成功生成了一个令牌。转到我的 api (laravel),不幸的是,即使存在 Authorization 标头,我也无法访问受 auth0.jwt 中间件保护的任何路由。它的回复是一个简单的文字,上面写着Unauthorized user。
我正在使用 Chrome 邮递员来测试我的 api 上的路线。
我试图通过检查vendor\auth0\login\src\Auth0\Login\Middleware\Auth0JWTMiddleware.php 来追踪负责响应的函数,发现CoreException 正在被抛出。
这里是 Auth0JWTMIddleware 的句柄方法:
/**
* @param $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, \Closure $next)
{
$auth0 = \App::make('auth0');
$token = $this->getToken($request);
if (!$this->validateToken($token)) {
return \Response::make('Unauthorized user', 401);
}
if ($token) {
try {
$jwtUser = $auth0->decodeJWT($token);
} catch (CoreException $e) {
return \Response::make('Unauthorized user', 401);
} catch (InvalidTokenException $e) {
return \Response::make('Unauthorized user', 401);
}
// if it does not represent a valid user, return a HTTP 401
$user = $this->userRepository->getUserByDecodedJWT($jwtUser);
if (!$user) {
return \Response::make('Unauthorized user', 401);
}
// lets log the user in so it is accessible
\Auth::login($user);
}
// continue the execution
return $next($request);
}
我怀疑从 Auth0 生成的令牌有更新的算法或其他东西,而 Laravel Auth0 包还不支持它。
我完全按照 Auth0 提供的文档进行操作,我还克隆了他们的示例项目,以确保配置正确,但不幸的是它也不起作用。关于如何解决我的问题的任何想法或想法?提前致谢!
【问题讨论】:
-
你好,我遇到了同样的问题,我通过 var_dumping 整个过程解决了这个问题,我发现我必须把 'secret_base64_encoded' => false 放在 laravel-auth0.php 中,如果这有帮助的话你 ! :)
标签: php angularjs laravel jwt auth0