ready to develop Mini Program, first test the background API, project to develop using Laravl+jwt+dingo. JWT wants to find such a middleware on the Internet during painless refresh token, testing
public function handle($request, Closure $next)
{
// token
$this->checkForToken($request);
// try token TokenExpiredException
try {
//
if ($this->auth->parseToken()->authenticate()) {
return $next($request);
}
throw new UnauthorizedHttpException("jwt-auth", "");
} catch (TokenExpiredException $exception) {
// token TokenExpiredException token
try {
// token
$token = $this->auth->refresh();
//
Auth::guard("api")->onceUsingId($this->auth->manager()->getPayloadFactory()->buildClaimsCollection()->toPlainArray()["sub"]);
} catch (JWTException $exception) {
// refresh
throw new UnauthorizedHttpException("jwt-auth", $exception->getMessage());
}
}
// token
return $this->setAuthenticationHeader($next($request), $token);
}
after testing the interface in postman, there is no way to add authorization
$this- > setAuthenticationHeader in response to header after each request. The source code is:
protected function setAuthenticationHeader($response, $token = null)
{
$token = $token ?: $this->auth->refresh();
$response->headers->set("Authorization", "Bearer ".$token);
return $response;
}
$response- > headers- > set ("Authorization"," Bearer". $token); cannot be added here. Why?
finally switch to this way:
return $next($request)->withHeaders([
"Authorization"=> "Bearer ".$token,
]);
there should be no problem with the method that comes with dingo. Is there something wrong with me?