我正在使用oauth2服务器laravel包,我是oauth的新手。我正在尝试实现这个库的密码流方法。我一直纠结于如何给出client_id和client_secret。
这是我的路线:
Route::post('oauth', function()
{
return AuthorizationServer::performAccessTokenFlow();
});
这给出的响应为-
{
"error": "invalid_request",
"error_description": "The user credentials were incorrect."
}
我已经从mysql中插入了client_id和client_secret。还种子用户表。
那么,为什么这在响应中显示错误呢?我做错了什么?
对于想要使用用户名而不是电子邮件(这是文档中宣传的方法)的新手,请在oauth2.php:中更改为以下内容
'grant_types' => [
'password' => [
'class' => ''League'OAuth2'Server'Grant'PasswordGrant',
'callback' => function($username, $password) {
if( Auth::validate([
'name' => $username,
'password' => $password,
])){
$user = 'App'User::where('name',$username)->first();
return $user->id;
} else {
return false;
}
},
'access_token_ttl' => 3600
]
]