2017-05-17 7 views
0

mongodb (Jenssegers Mongodb)를 사용하여 예제 Laravel 프로젝트를 작성했으며 Laravel 5.4의 여권을 사용합니다. by this document을 따르십시오. 내가 테스트를 위해 우편 배달에 액세스 토큰을했다 때까지Laravel 5.4 mongodb 여권 액세스 토큰 Unauthenticated

모든 것이 잘 작동, 지금 Accept: application/jsonAuthorization: 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.phptry 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'); 
} 

어떤 아이디어가 있습니까?

답변

0

깊은 곳에서 몇 시간 파고 들어서 vendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.php에 도착했습니다. 해결책을 찾았습니다. 내가 Mobodb를 사용하고이 기능이 use Jenssegers\Mongodb\Eloquent\Model를 사용하고 그것을 _id 대신 id를 검색하기 때문에

문제는 기능 public function find($id) 라인 (27)

public function find($id) 
{ 
    return Token::find($id); 
} 

에서 파일 vendor\laravel\passport\src\TokenRepository.php입니다. 따라서, 이와 같은 기능을 찾기 위해 변경을해야합니다.

public function find($id) 
{ 
    return Token::where('id', $id)->first(); 
} 

수정 벤더 파일이 권장되지는 않지만

,하지만 난 희망 다음 버전에서, Laravel 여권의 저자는 여권 지원하여 MongoDB를 발표 할 예정이다, 그렇게해야이 경우이다.

희망이 도움이 누군가.