【问题标题】:How to authenticate Facebook users using jwt-auth?如何使用 jwt-auth 对 Facebook 用户进行身份验证?
【发布时间】:2015-06-03 10:04:13
【问题描述】:

我正在使用 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);
    }

错误:

ErrorException in EloquentUserProvider.php line 108:
Undefined index: password

【问题讨论】:

  • 你能为 EloquentUserProvider.php 提供 pastebin 吗?看来您正在使用 $password,但未定义变量。
  • @ChainList 是的,我没有提供密码参数,因为用户来自 facebook。所以我只有 fb_id 和电子邮件来验证用户身份。

标签: php facebook authentication laravel-5 jwt


【解决方案1】:

更新: 设法通过使用 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);

【讨论】:

  • 你好。这个用户在哪里?可以给我写详细的说明吗
猜你喜欢
  • 2014-07-29
  • 2016-05-16
  • 2018-12-29
  • 1970-01-01
  • 2020-12-04
  • 2016-04-07
  • 2011-08-12
  • 1970-01-01
  • 2020-01-03
相关资源
最近更新 更多