流明生成令牌而不验证用户名和密码

use*_*153 8 jwt laravel lumen

我试图通过验证其他字段和表而不是用户表的电子邮件和密码来生成令牌.我正在使用tymon jwt图书馆.

我有三个字段需要验证才能验证用户身份

 table::where(["id"=>"1","mobile"=>"123","otp"=>"asdf"])->get();
Run Code Online (Sandbox Code Playgroud)

因此,如果我在表中找到符合此条件的行,那么我想验证用户并生成带有所需声明的有效令牌.

到目前为止我尝试过的是:

//after check for three fields in DB. If row matches then, $id and $contact are variable from DB.
$customClaims = ['id' => $id, 'mobile' => $contact];

$payload = JWTFactory::make($customClaims);
Run Code Online (Sandbox Code Playgroud)

在尝试这个时,我得到了JWT payload does not contain the required claims.

那么如何使用三个字段对用户进行身份验证并生成带有所需声明的有效令牌$customClaims.

编辑

 public function verifyOTP(Request $request) {
    $otp = $request->otp;
    $schoolid = $request->schoolid;
    $parent_contact = $request->contactNum;
    $verifyOTP = OTP::where(['schoolid' => $schoolid, 'parent_numb' => $parent_contact, 'otp' => $otp])->get();
    if ($verifyOTP) {

        $customClaims = ['schoolid' => $schoolid, 'parent_numb' => $parent_contact];

        $payload = JWTFactory::make($customClaims);

        $token = JWTAuth::encode($payload);
        return $token;
    }
}
Run Code Online (Sandbox Code Playgroud)

Gab*_*iel 0

这样的话Crypt就会变得这么好用,不知道以后要不要做任何认证。Crypt 将帮助您加密和解密。

创建特征或任何其他类,您不必太担心加密和解密,Crypt 可以照顾。我使用Crypt构建了移动 API

加密:Crypt::加密($value);

解密: Crypt::decrypt($value);

更多信息: https: //laravel.com/docs/5.2/encryption

  • 这甚至是对上述问题的答案吗?它如何解决 JWT 中缺失声明的 OP 问题? (2认同)