Wre*_*cks 2 php authentication facebook jwt laravel-5
我使用Laravel 5和jwt-auth包来处理JWT.如果用户来自Facebook,我该如何进行身份验证?
我的想法是,我将使用FB ID和电子邮件进行身份验证.我通过将密码更改为fb_id来做到这一点,不幸的是它没有用.任何建议,为什么我会得到以下错误?谢谢!
验证码:
//facebook
if(Input::has('fb_id')){
$credentials = Input::only('email','fb_id');
}else{
$credentials = Input::only('email', 'password');
}
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return Response::json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return Response::json(['error' => 'could_not_create_token'], 500);
}
Run Code Online (Sandbox Code Playgroud)
错误:
ErrorException in EloquentUserProvider.php line 108:
Undefined index: password
Run Code Online (Sandbox Code Playgroud)
更新:通过使用JWTAuth :: fromUser($ user)进行管理以使其工作.
//find the user using his details.
$user = User::where('email','=',Input::get('email'))->where('fb_token','=',Input::get('fb_id'))->first();
//then use
$token = JWTAuth::fromUser($user);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2536 次 |
最近记录: |