티스토리 뷰
[angularjs] jwt auth laravel 5가 오류를 제공함 The token could not be parsed from the request
필살기쓰세요 2021. 2. 21. 15:26You need to send authorization token in the header. You might need to modify your Apache settings to allow for authorization headers to be sent.
Authorization: Bearer {yourtokenhere}
You can modify your .htaccess file with:
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
-------------------
JWTAuth::parseToken()
requires token to be sent in the header in the following format:
Authorization: Bearer {yourtokenhere}
And I believe, you don't do that. So, your getAuthenticatedUser
fails.
-------------------
You might try to set always_populate_raw_post_data = -1 in php.ini
This worked for me
-------------------
나는 추측
LoginController::getAuthenticatedUser()
사용자의 자격 증명 (이메일과 비밀번호)을 인증하는 것 같다.그러나도있다
JWTAuth::parseToken()->authenticate($email, $password)
에
getAuthenticatedUser()
방법. 이 (
JWTAuth::parseToken()
가) 요청
1
에서 토큰의 유효성을 검사합니다 . 클라이언트 는 토큰과 함께
GET / api / authenticate
엔드 포인트에 요청을 보내야합니다 .제 생각에는
LoginController::authenticate()
JSON Web Token으로 사용자 정보를 식별하고 클라이언트에 응답합니다.
email
및
password
매개 변수에 필요하지 않은
LoginController:: getAuthenticatedUser()
토큰이 사용자를 식별 할 수 있기 때문에.
LoginController.php
public function getAuthenticatedUser(){
try{
if(! $user = JWTAuth::parseToken()->authenticate()){
return \Response::json(['user_not_found'], 404);
}
}
catch(Tymon\JWTAuth\Exceptions\TokenExpiredException $e){
return \Response::json(['token_expired'], $e->getStatusCode());
}
catch(Tymon\JWTAuth\Exceptions\TokenInvalidException $e){
return \Response::json(['token_invalid'], $e->getStatusCode());
}
catch(Tymon\JWTAuth\Exceptions\JWTException $e){
return \Response::json(['token_absent'], $e->getStatusCode());
}
return \Response::json(compact('user'));
/*return \Response::json(array('user' => 'Steve', 'state' => 'CA'));*/
}
-------------------
간단한 편집 .htaccess 파일. 즉, /public/.htaccess 내부
옵션-MultiView
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
출처
https://stackoverflow.com/questions/39940217