私はmongodb(Jenssegers Mongodb)を使ってLaravelプロジェクトのサンプルを作成しました.Laravel 5.4のパスポートはby this documentに従っています。私はテストのためのポストマンにアクセストークンを取ったまでLaravel 5.4 mongodbパスポートアクセストークンUnauthenticated
すべてが正常に動作し、今Accept: application/json
とAuthorization: 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');
}