PHP身份验证API



我想了解如何使用邮政和格式制作PHP API的建议会导致JSON(最好使用Laravel(。API需要使用这些参数来验证用户凭据(电子邮件地址,密码,令牌(。

响应200:

{
    "data": [
        {
            "id": 1,
            "email_address": test@gmail.com,
            "authenticated": true,
            "type": password,
            "timestamp": 436543678572,
            "last_login": 436543678572,
            "session_expires": 436543678572
        },
    ],
}

与SSO的响应200:

{
    "data": [
        {
            "id": 1,
            "email_address": test@gmail.com,
            "authenticated": true,
            "type": sso,
            "timestamp": 436543678572,
            "last_login": 436543678572,
            "session_expires": 436543678572
        },
    ],
}

很容易使用https://jwt.io(laravel库:https://github.com/tymondesigns/jwt-auth(,将所需的响应信息放在您的getJWTCustomClaims上用户模型

public function getJWTCustomClaims()
{
    return [
        'user' => [
            'id'     => $this->id,
            'name'   => $this->user_name,
        ]
    ];
}

以及前端层中的每个位置,您都可以从令牌有效载荷中检索信息。

最新更新