我想使用Laravel Passport令牌构建Laravel rest api。
我使用客户端密钥生成了access_token,并且获得了访问令牌,但是当我想使用访问令牌访问api时,总是会收到消息"exception 'BadMethodCallException' with message 'This token is not signed' in /vendor/lcobucci/jwt/src/Token.php:194"
。
如何解决此错误?
我尝试生成新密钥,并使用php artisan cache:clear
清除缓存,但没有用
这是我生成令牌的代码 1.使用客户端密钥生成访问令牌
网址:https://xxxxx/oauth/token
参数
{
"grant_type":"client_credentials",
"client_id":"41",
"scope":"*",
"client_secret":"CFprIY1qWznahoKDMomTAqLUx6IALfWR0xLwKjwA"
}
响应
{
"token_type": "Bearer",
"expires_in": 300,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjIxYTg4NzQ2YmE1N2U5OGE3NDZlZDg5MmUyYjU3ZmZkOGFkNjJlYWZiMWNjMzk0MDU2NGQ1N2ZjZjE2MDcwYzFjMjYwYTE1MGU1N2MzYzQyIn0.eyJhdWQiOiI0MSIsImp0aSI6IjIxYTg4NzQ2YmE1N2U5OGE3NDZlZDg5MmUyYjU3ZmZkOGFkNjJlYWZiMWNjMzk0MDU2NGQ1N2ZjZjE2MDcwYzFjMjYwYTE1MGU1N2MzYzQyIiwiaWF0IjoxNTU3NzMzMzc2LCJuYmYiOjE1NTc3MzMzNzYsImV4cCI6MTU1NzczMzY3Niwic3ViIjoiIiwic2NvcGVzIjpbXX0.GGKOd-WRBT-UNmdDJe2WdUmatrumbwlDLlP0f1LKrAikU3JhwG8xkD4iLDUwmcaT5S37-GUSrdWjI3nnzNkAyFexLLJH7Vr6n7QsskWLH80ZR5mTaFXLgmsprp15UeoXm3op52Pa-Hq2mqx3C_nxQNxLElF68obApVhuYDLd2u46YP0b_DoYJqqg85sLGHyUsC95ofkMytmMc_aVoiOS1UmAoSn597p5ovJ3F47MakyuezduBvFWlA4wKxsW1wHjRe_4AkldzGhif16p_lbdBNg2HR-zQXYkmMHBjqLUd17R3w7fyOi5C_Z02gEkH78KqPP2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VPaVlfVbHRripqPKXOv8JmkE4vxGBS-abtrBQmRfU-jNgmTvkcVHSAWyycLKY8NiRUmWwFHly-IfviWxDnOEOYVDzY5ZaP0TGapZRpQEVBW12QauGtlxZ76NOxb9RZVX_dTgfXvS22icGW0XJPPM8eobYeyzwZvpBovBnCxJxKp_EgJZPeTG1bBzwderp1b3OXNc2gF_U2iUAxAIMohKKAe0JFzNe0bmsueQOLul8jc9ZjxP2Km2a5OHxnvTK_5dBWFN62yuGkJb8JJz5U5beUTbIaPPmJqu7n8rqyz3E5IGmxQUH0XES_ZMayMrvwI03PLQVmtngCb2MeOZjxRll3GtJGlpXYhoTPCeyQz7m-VWaCkNgfohEtt-1W7tGU8X_sMwNwyKRhzjM
[{"key":"Accept","value":"application/json","description":"","type":"text","enabled":true}]
结果:
development.ERROR: exception 'BadMethodCallException' with message 'This token is not signed' in /xxxxxxvendor/lcobucci/jwt/src/Token.php:194
答案 0 :(得分:0)
我认为您已经错过了User.php中的特征HasApiTokens
请添加以下特征
use HasApiTokens,Notifiable;