如何在 laravel 中使用护照检索访问令牌?
How to retrieve access token with passport in laravel?
我只是按照 Laravel official 中的步骤操作。
我正在使用 postman 发送 post 请求 (http://localhost:7777/my-project/public/oauth/token ) 所以我可以检索访问令牌:
{
"grant_type" : "password",
"client_id" : "2",
"client_secret" : "oxKBv6EnyEXeF6l4FBbkVcLgq2WPnyB9EOdlUpL5",
"username" : "my_email",
"password" : "my_password",
"scope" :""
}
我收到这个错误:
{"error":"invalid_credentials","message":"The user credentials were incorrect."}
即使我确定我的凭据是正确的。
您的客户端必须设置为密码授予客户端才能使用密码授予:
https://laravel.com/docs/5.5/passport#creating-a-password-grant-client
普通客户端没有启用密码授权。
post 人
Accept : application/json
Authorization : Bearer token //here pass token and token is equal to your login time token(write like Bearer space token)
请检查您 oauth_clients table - 确保:
你的client_id是正确的
你的client_secret是正确的
您的客户端 password_client 值设置为 1
可能问题出在最后一部分。
如果您使用客户端凭据访问OAuth令牌然后使用grant_type是client_credentials
{
"grant_type" : "client_credentials",
"client_id" : "2",
"client_secret" : "oxKBv6EnyEXeF6l4FBbkVcLgq2WPnyB9EOdlUpL5",
"username" : "my_email",
"password" : "my_password",
"scope" :""
}
下面是一些文档:- https://laravel.com/docs/5.4/passport#client-credentials-grant-tokens
我只是按照 Laravel official 中的步骤操作。
我正在使用 postman 发送 post 请求 (http://localhost:7777/my-project/public/oauth/token ) 所以我可以检索访问令牌:
{
"grant_type" : "password",
"client_id" : "2",
"client_secret" : "oxKBv6EnyEXeF6l4FBbkVcLgq2WPnyB9EOdlUpL5",
"username" : "my_email",
"password" : "my_password",
"scope" :""
}
我收到这个错误:
{"error":"invalid_credentials","message":"The user credentials were incorrect."}
即使我确定我的凭据是正确的。
您的客户端必须设置为密码授予客户端才能使用密码授予:
https://laravel.com/docs/5.5/passport#creating-a-password-grant-client
普通客户端没有启用密码授权。
post 人
Accept : application/json
Authorization : Bearer token //here pass token and token is equal to your login time token(write like Bearer space token)
请检查您 oauth_clients table - 确保:
你的client_id是正确的
你的client_secret是正确的
您的客户端 password_client 值设置为 1
可能问题出在最后一部分。
如果您使用客户端凭据访问OAuth令牌然后使用grant_type是client_credentials
{
"grant_type" : "client_credentials",
"client_id" : "2",
"client_secret" : "oxKBv6EnyEXeF6l4FBbkVcLgq2WPnyB9EOdlUpL5",
"username" : "my_email",
"password" : "my_password",
"scope" :""
}
下面是一些文档:- https://laravel.com/docs/5.4/passport#client-credentials-grant-tokens