【问题标题】:PHP Authenticate APIPHP 身份验证 API
【发布时间】:2018-10-08 20:34:44
【问题描述】:

我想了解如何使用 POST 制作 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
        },
    ],
}

【问题讨论】:

  • 你可以使用智威汤逊或护照

标签: php laravel laravel-5


【解决方案1】:

您可以轻松使用https://jwt.io(laravel 库:https://github.com/tymondesigns/jwt-auth),将您想要的响应信息放在您的用户模型的getJWTCustomClaims 上

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

在前端层的每个地方,您都可以从令牌负载中检索信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-23
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    相关资源
    最近更新 更多