mongodb (Jenssegers Mongodb)를 사용하여 예제 Laravel 프로젝트를 작성했으며 Laravel 5.4의 여권을 사용합니다. by this document을 따르십시오. 내가 테스트를 위해 우편 배달에 액세스 토큰을했다 때까지Laravel 5.4 mongodb 여권 액세스 토큰 Unauthenticated
모든 것이 잘 작동, 지금 Accept: application/json
및 Authorization: Bearer $TOKEN
입니다 I 설정이 헤더 내 api.php
경로 우체부에서
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
를 살펴보고 나는 매우 해요 내 액세스 토큰이 복사본 누락 오류가 아니지만 오류가 계속 발생하는지 확인하십시오. 내가 모델에 덮어 쓰기 기본 id
필드가
을 시도했습니다
{
"error": "Unauthenticated."
}
것 User.php
use Authenticatable, Authorizable, CanResetPassword, Notifiable, HasApiTokens;
protected $collection = 'users';
protected $fillable = ['username', 'email', 'password', 'name'];
protected $primaryKey = '_id';
나 또한 그렇게 public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::tokensExpireIn(Carbon::now()->addYears(20));//You can also use addDays(10)
Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));//You can also use addDays(10)
Passport::pruneRevokedTokens(); //basic garbage collector
Passport::tokensCan([
'conference' => 'Access your conference information'
]);
}
처럼 AuthserviceProvider.php
에서 토큰 만료 시간을 수정
그리고 다른 방법은 있지만 여전히 작동하지 않습니다. 내가 line 66
에서 파일 vendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.php
을 검사 할 때 디버그 정보]
내가 public/index.php
에 try catch
를 추가하기위한
UPDATE는 오류가
League\OAuth2\Server\Exception\OAuthServerException: The resource owner or authorization server denied the request. in /data/www/public_html/xxxx/vendor/league/oauth2-server/src/Exception/OAuthServerException.php:165 Stack trace: #0 /data/www/public_html/xxxx/vendor/league/oauth2-server/src/AuthorizationValidators/BearerTokenValidator.php(66): League\OAuth2\Server\Exception\OAuthServerException::accessDenied('Access token ha...') #1 /data/www/public_html/xxxx/vendor/league/oauth2-server/src/ResourceServer.php(82): League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator->validateAuthorization(Object(Zend\Diactoros\ServerRequest)) ......
을 apperead. 내 액세스 토큰이 취소 된 것으로 보이지만 데이터베이스 revoked
열이 여전히 거짓이며이 액세스 토큰은 아주 새 것입니다. 몇 분 전에 작성했습니다. if ($this->accessTokenRepository->isAccessTokenRevoked($token->getClaim('jti'))) {
throw OAuthServerException::accessDenied('Access token has been revoked');
}
어떤 아이디어가 있습니까?