2017-05-17 2 views
0

私はmongodb(Jenssegers Mongodb)を使ってLaravelプロジェクトのサンプルを作成しました.Laravel 5.4のパスポートはby this documentに従っています。私はテストのためのポストマンにアクセストークンを取ったまでLaravel 5.4 mongodbパスポートアクセストークンUnauthenticated

すべてが正常に動作し、今Accept: application/jsonAuthorization: Bearer $TOKENをしている私のセットアップ2つのヘッダ、私の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にトークンの有効期限を変更

そしていくつかの他の方法は、まだ動作しません。

デバッグINFOMATIONのためのUPDATE

私はpublic/index.phpにしてtry catchを追加すると、私はline 66でファイルvendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.phpをチェックすると、エラーが

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の列はまだfalseであり、このアクセストークンはまったく新しいもので、数分前に作成したばかりである。

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を探しているので

問題は、機能でファイルvendor\laravel\passport\src\TokenRepository.phppublic function find($id)ライン27

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

です。ですから、このような機能を変更する必要があります。修正ベンダーファイルが、

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

はお勧めしますが、この場合には、私はそれを行う必要があり、うまくいけば次のバージョンでは、Laravelのパスポートの著者は、パスポートのサポートにMongoDBをリリースする予定はありません。

願っています。