jscustom/laravel-sanctum-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jscustom/laravel-sanctum-auth

Composer 安装命令:

composer require jscustom/laravel-sanctum-auth

包简介

Laravel package for user authentication.

README 文档

README

Laravel package for sanctum authenticator. Includes login, register, logout, change password and forgot password.

Table of Contents

Getting Started
Prerequisite(s)
Installation
How to Use
Download Postman API
Sanctum Authenticator
Login API
Register API
Logout API
Change Password API
Forgot Password (Send Request) API
Forgot Password (Reset) API
Support

Getting Started

Below are the steps in order to integrate sanctum authenticator API to your Laravel project.

Prerequisite(s)

Laravel Sanctum

Install Laravel Sanctum via Composer:

composer require laravel/sanctum

Uncomment \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class located in the app/Http/Kernel.php file

'api' => [
  \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
  'throttle:api',
  \Illuminate\Routing\Middleware\SubstituteBindings::class,
]

Add the following lines of code to the $routeMiddleware variable in the app/Http/Kernel.php file

'abilities' => \Laravel\Sanctum\Http\Middleware\CheckAbilities::class,
'ability' => \Laravel\Sanctum\Http\Middleware\CheckForAnyAbility::class

Installation

Install the package using composer:

composer require jscustom/laravel-sanctum-auth

Export the configuration file:

php artisan vendor:publish --provider="JSCustom\LaravelSanctumAuth\Providers\LaravelSanctumAuthServiceProvider" --tag="config"

Export the migration files:

php artisan vendor:publish --provider="JSCustom\LaravelSanctumAuth\Providers\LaravelSanctumAuthServiceProvider" --tag="migrations"

Do a quick migration:

php artisan migrate --path=/database/migrations/laravel-sanctum-auth

How To Use

Download Postman API

Download the Postman API Collection here.

Sanctum Authenticator

Features

  • Login
  • Register
  • Logout
  • Change Password
  • Forgot Password (Send Request)
  • Forgot Password (Reset)

Models

JSCustom\LaravelSanctumAuth\Models\User
JSCustom\LaravelSanctumAuth\Models\UserProfile
JSCustom\LaravelSanctumAuth\Models\UserRole
JSCustom\LaravelSanctumAuth\Models\PasswordReset

Login API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/login

Form Data

{
  "username": "stevengrant",
  "email": "stevengrant@mail.com",
  "password": "yourpasswordhere",
}

Method

POST

Headers

{
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "Welcome, Steven!",
  "payload": {
    "user": {
      "id": 1,
      "username": "stevengrant",
      "email": "stevengrant@mail.com",
      "status": 1,
      "role_id": 2,
      "email_verified_at": null,
      "created_at": "2022-06-14T23:27:07.000000Z",
      "updated_at": "2022-06-15T14:14:18.000000Z",
      "user_profile": {
        "id": 1,
        "user_id": 1,
        "first_name": "Steven",
        "last_name": "Grant",
        "created_at": "2022-06-14T23:24:42.000000Z",
        "updated_at": "2022-06-14T23:24:42.000000Z"
      },
      "user_role": {
        "id": 2,
        "role": "Regular User",
        "description": "Regular User description here",
        "created_at": "2022-06-14T23:24:42.000000Z",
        "updated_at": "2022-06-14T23:24:42.000000Z"
      }
    },
    "access_token": "4|SvOITBX0p79AujrZQFse75TJJgONp3kYuid7Q0uP"
  }
}

Register API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/register

Form Data

{
  "username": "markanthony",
  "email": "markanthony@mail.com",
  "status": 1,
  "role_id": 1,
  "first_name": "Mark",
  "last_name": "Anthony",
  "password": "yourpasswordhere"
}

Method

POST

Headers

{
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "Register success.",
  "payload": {
    "user": {
      "username": "markanthony",
      "email": "markanthony@mail.com",
      "status": 1,
      "role_id": 1,
      "updated_at": "2022-06-15T14:33:56.000000Z",
      "created_at": "2022-06-15T14:33:56.000000Z",
      "id": 8,
      "password_unhashed": "yourpasswordhere",
      "user_role": {
        "id": 1,
        "role": "Regular User",
        "description": "Regular User description here",
        "created_at": "2022-06-14T23:24:42.000000Z",
        "updated_at": "2022-06-14T23:24:42.000000Z"
      },
      "user_profile": {
        "id": 4,
        "user_id": 8,
        "first_name": "Mark",
        "last_name": "Anthony",
        "created_at": "2022-06-15T14:33:56.000000Z",
        "updated_at": "2022-06-15T14:33:56.000000Z"
      }
    }
  }
}

Logout API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/logout

Method

POST

Headers

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "Logout successful."
}

Change Password API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/change-password

Parameters

{
  "current_password": "yourcurrentpassword",
  "new_password": "yournewpassword",
  "new_password_confirmation": "yournewpassword"
}

Method

POST

Headers

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "Password updated successfully."
}

Forgot Password (Send Request) API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/forgot-password

Parameters

{
  "email": "markanthony@mail.com"
}

Method

POST

Headers

{
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "A forgot password request was sent to your email.",
  "payload": {
    "reset_password_token": "$2y$10$ELeKX3zUOBMQJSmuFdaAwOf7id7NNuxXwydfwL/.sIUdEZ35gwi7y"
  }
}

Forgot Password (Reset) API

Controller

\JSCustom\LaravelSanctumAuth\Http\Controllers\Authenticator\AuthenticatorController

URL

{{url}}/api/auth/reset-password

Parameters

{
  "new_password": "yournewpassword",
  "new_password_confirmation": "yournewpassword",
  "reset_password_token": "$2y$10$IqsuRxB5ugH/aui3PCNzPeWBBKilUc3Cgy1K/F48NkgJ/O4kbO0bC"
}

Method

POST

Headers

{
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "Password reset successfully."
}

Support

For support, email developer.jeddsaliba@gmail.com.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固