使用vagrant / homestead设置Laravel的5.3 Passport。一直到我到达Password Grant Tokens
在这里,我发现这个GuzzleHttp片段发布到/oath/token
:
Route::get('/api_grant', function(){
$http = new GuzzleHttp\Client;
$response = $http->post('http://mavrik-cms.io/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => '6',
'client_secret' => 'BBlhjUlGsbde5zQ3LBHAr6inJoQVFOMIZlR1RFUI',
'username' => 'mrricki.m.usmc@gmail.com',
'password' => 'secret',
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
});
虽然我已经发送了所有必需和正确的信息,但我仍然收到:(注意:我是唯一的用户,因此我的电子邮件和虚拟密码以及客户端与oauth客户端表上的user_id正确关联,而password_client是设为1);
{"error":"invalid_credentials","message":"The user credentials were incorrect."}
我已经乱了几个小时了。我已经尝试了所有可能的用户和密码组合。(用户模型的电子邮件作为用户名,用户模型的用户名为用户名,用户模型的密码作为密码等)。
答案 0 :(得分:1)
我也遇到了同样的问题,但我通过bcrypting表中的用户密码解决了这个问题 您可以在此处联机密码http://bcrypthashgenerator.apphb.com/,然后将密码保存在针对特定用户的表格中
此外,您必须在发布数据中的用户名密钥中传递emailid(列中的值'电子邮件'
)答案 1 :(得分:0)
您可以使用Hash::make('your_password')
或bcrypt('your_password')
之类的东西! ;)
答案 2 :(得分:0)
我在那里更改文件
app \ Http \ Kernel.php更改'auth'=> \ App \ Http \ Middleware \ Authenticate :: class对此
'auth' => \Illuminate\Auth\Middleware\Authenticate::class
将此功能添加到用户类或添加客户端模式。
public static function findForPassport( YOUR PARAMERT )
{
return User::where('mobile', YOUR PARAMERT)->first();
}
我的Client.php
use Notifiable,HasApiTokens;
protected $fillable = [
'name', 'mobile', 'email', 'avatar','password','active','enterprise_id'
];
public $timestamps = true;
Protected $hidden = [
'password', 'remember_token',
];
public static function findForPassport($mobile)
{
return User::where('mobile', $mobile)->first();
}
在发送令牌后获取用户信息,我使用此代码
$request->user('api');
以这种方式在api.php文件中测试您的api
Route::get('/user', function (Request $request) {
return $request->user('api');
});
如果用户登录,您将获得用户信息