Looking to hire Laravel developers? Try LaraJobs

laravel-sanctum-auth maintained by jscustom

Description
Laravel package for user authentication.
Last update
2022/06/18 14:27 (dev-master)
License
Links
Downloads
4

Comments
comments powered by Disqus

Laravel Sanctum Authenticator API

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.