我试图通过验证其他字段和表而不是用户表的电子邮件和密码来生成令牌.我正在使用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)
这样的话Crypt就会变得这么好用,不知道以后要不要做任何认证。Crypt 将帮助您加密和解密。
创建特征或任何其他类,您不必太担心加密和解密,Crypt 可以照顾。我使用Crypt构建了移动 API
加密:Crypt::加密($value);
解密: Crypt::decrypt($value);
更多信息: https: //laravel.com/docs/5.2/encryption
归档时间: |
|
查看次数: |
596 次 |
最近记录: |