datakrama/lapiuth

此包已被废弃,不再维护。未建议替代包。

Laravel API 身份验证,将默认身份验证更改为 API 友好型

v2.1.0 2020-11-06 05:44 UTC

This package is auto-updated.

Last update: 2020-11-06 05:55:32 UTC


README

Run Tests

众所周知,Laravel 提供了内置的认证功能。但是,这仅适用于 Web,而不是 API。正因为如此,才有了 Lapiuth。

Lapiuth 是为 Laravel 基础 API 服务器提供的即用型认证库。这个库很简单。但,它仍然可以帮助我们完成工作。我们希望对你也是如此。

要求

Laravel 兼容性

Laravel
6.x 1.x
7.x 2.x

安装

在使用此包之前,请确保您已设置 Passport 个人访问令牌。您可以在 https://laravel.net.cn/docs/7.x/passport 查看文档。

$ composer require datakrama/lapiuth:"~2.0"

用法

发布

要发布配置,只需运行此命令

$ php artisan vendor:publish --provider="Datakrama\Lapiuth\ServiceProvider"

在此配置中,您可以更改客户端的 URL、密码 URL 和电子邮件验证 URL。

认证的模型特质

由于此包使用默认的认证,您可以在认证模型中使用特质,就像 Laravel 一样。您可以使用两个特质,Datakrama\Lapiuth\Traits\CanResetPasswordDatakrama\Lapiuth\Traits\MustVerifyEmail。每个特质用于重置密码和电子邮件验证。

示例

<?php

namespace App;

use Datakrama\Eloquid\Traits\Uuids;
use Datakrama\Lapiuth\Traits\CanResetPassword;
use Datakrama\Lapiuth\Traits\MustVerifyEmail as MustVerificationEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements MustVerifyEmail
{
    use Uuids, HasApiTokens, HasRoles, Notifiable, CanResetPassword, MustVerificationEmail;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'id', 'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。