0
votes

i followed this steps :

  1. installed passport package as it's documentation
  2. created a user with db:seed (i was surprised to see api_token column not exist error.. over all i added this column manually )
  3. created a user with db:seed (i don't know what is api_token for but i filled it randomly)
  4. successfully generated a access token via password credentials over http://localhost:8000/oauth/token

the problem is when consuming the generated token i always got

{"message":"Unauthenticated."}

sample of generated token :

{
    "token_type": "Bearer",
    "expires_in": 31536000,
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImNhNjdlNTA5MDI0M2FhZjMwNDViZGQ1OTc5MDI3YTc4ODA4MWFiMTA4NDk5OThmZTE0NmJhYmRiZmNkYzRlN2MxNjcyZDdhZjdmNTU4Y2Y4In0.eyJhdWQiOiIyIiwianRpIjoiY2E2N2U1MDkwMjQzYWFmMzA0NWJkZDU5NzkwMjdhNzg4MDgxYWIxMDg0OTk5OGZlMTQ2YmFiZGJmY2RjNGU3YzE2NzJkN2FmN2Y1NThjZjgiLCJpYXQiOjE1NDEyNjE5MTYsIm5iZiI6MTU0MTI2MTkxNiwiZXhwIjoxNTcyNzk3OTE2LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.JuTqO1W9gSLq1gA0ku8snsfaZXvX08Rjr_KbFtLzNOgP1mpzLbkOT7QzwdBVwOU4Fq6qUaZYP7bTKVPOSr9D8kBJLHEvN83vG-7JnSK87128bVVL1SCI31-ZsyG53LU0py2HOsycgZup7X3NXweDQ9YFNDZneuWASNhb5j06didSZ_p4C1eON3ptjnay1H2zjYHZoQ2prFQgi-ZQpXxt3c_4WhciDb-Yb8a8VBdub1mvj5gMF8kkrTN9cLlIpTFDsxGJTAkD0wYCX0W_I6Aggjc5YSEK_ovYJ5b4Ag2B8chrKqLXvRbplYkMCypsNxyR-OMJe0VCOISvutUdvU0UU7JvbyEoE45uFzV6wAqDMXQF0G10Sd1QB5fSzWHjj2pBonjnYGrEOynXpt8AGmU-Ip53rHAC3k7Tif0CE5QQ-kFJ01b-BW-MQp2MFwRRHZTOkXSnsfGocZBaryTHfgdGMPS7hcxJDh-l7h1g6wq6ywNIevI-XiUaC_XjrSUn-uUe4J1XtK1S6wM58OeprLtfbsleYOoYH2nnmZ6eXpCaeS3ENVTnT5t3sJV_TgUfR8hOuPlCB8uqFNE9atBGgP2fiNcgNkyu5uG0AXM3_drvgsSumyvJYXLRMfkHeaAA3HTWKzUck-yhxuSqNpTZPMt-Ml1FzNx4ABUQDB7WrXG3Rd0",
    "refresh_token": "def50200e277884b2343dc16700e2ccd4b6f46ae31131fc6dc4ef643204d74696dceafa430647d89732cf1a06c944f04583510afd1f53aa84cfacdc7fb81843ec163802922171451e0d2511788b7ee71d6e341ae07977c45f44373d9db2c65b81618dd7e0fe066a3f76c4339b6308a4561c23eb31b1fd291fbf91e379c98ca1ee0f7c689eac1aac2ea0b4a5468f954ea82d2aa5d505b38d92ccb9663b0ecefb3702903738bb843b1d8cd12a9feeefcb3705713cb7b699de02c4dafa32616caf9e32a965a30224a806d8b6cb776f81da0961ce1e2cd8348e7e2b8ffd42b0ba9fd9f9e1f34b6160f4ed1e41d778a8207e17ca512aee2368a43ec3bcc7b5897d2774fd94b3ff5e7ce2cc0ce386f42e4a43d4d49a126d629bc90aa72e087f67183509b739008ce73839801a58ff76f1c7d310e9ba79c52ec4758bdcfaa53e15ed286528ee27ac0e9e8498776920b8d1cd5d6aff4029b9fc19a02c8b71badd960f190a8"
}

my packages versions:

    "php": "^7.1.3",
    "barryvdh/laravel-cors": "^0.11.2",
    "fideloper/proxy": "^4.0",
    "laravel/framework": "5.7.*",
    "laravel/passport": "^7.0",
    "laravel/tinker": "^1.0",
    "spatie/laravel-permission": "^2.23"

middleware guard :

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

is there something i miss ?

update :

i noticed when i put each random string inside api_token column in user table i can easily authenticate user by passing that through Bearer Token

question: so after authenticating user by :

Auth::attempt($credentials)

should framework automatically fill token_api or i should fill it manually ?

1

1 Answers

0
votes

it turned to be the laravel caching problem :

  1. no need for token_api column for laravel/passport
  2. just run php artisan config:cache to reset cache