kawaiiwaifus/laravel-api-kawaii-jwt

REST API.

v0.0.3 2017-11-22 15:01 UTC

This package is not auto-updated.

Last update: 2024-04-18 17:02:39 UTC


README

Kawaii-jwt

  • Kawaii-jwt is API from Quasar BoilerPlate - BoilerPlate

ReLations packets:

Installation

  • composer create-project kawaiiwaifus/laravel-api-kawaii-jwt NameOfProject

Usage

  • run the php artisan migrate
  • run the php atisan jwt:secret
  • run the php artisan db:seed (optional) for create tests users.

Main Features

A Ready-To-Use Authentication Controllers

You don't have to worry about authentication and password recovery anymore. I created four controllers you can find in the App\Api\V1\Controllers for those operations.

For each controller there's an already setup route in routes/api.php file:

  • POST api/auth/login, to do the login and get your access token;
  • POST api/auth/refresh, to refresh an existent access token by getting a new one;
  • POST api/auth/register, to create a new user into your application;
  • POST api/auth/recovery, to recover your credentials;
  • POST api/auth/reset, to reset your password after the recovery;
  • POST api/auth/logout, to log out the user by invalidating the passed token;
  • GET api/auth/me, to get current user data;

Router ADM Users

  • GET api/admin/users, get all users
  • GET api/admin/users/{id}, get user to edit
  • PUT api/admin/users/{id}, update user
  • POST api/admin/users, "create user" I think not finished it.
  • DELETE api/admin/users/{id}, "delete user" I think not finished it.

--

Router Roles e Permissions

  • GET api/admin/roles, get all roles

  • GET api/admin/roles/{id}, get role to edit

  • PUT api/admin/roles/{id}, update role

  • POST api/admin/roles, create role

  • DELETE api/admin/roles/{id}, delete role

  • GET api/admin/permissions, get all permissions

  • GET api/admin/permissions/{id}, get permission to edit

  • PUT api/admin/permissions/{id}, update permission

  • POST api/admin/permissions, create permission

  • DELETE api/admin/permissions/{id}, delete permission

A Separate File for Routes

All the API routes can be found in the routes/api.php file. This also follow the Laravel 5.5.

Secrets Generation

Every time you create a new project starting from this repository, the php artisan jwt:generate command will be executed.

Configuration

Database example:

DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(125) COLLATE utf8_unicode_ci NOT NULL,
  `remember_token` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
  `telephone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `active` int(1) NOT NULL DEFAULT '0',
  `gender` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
  `address` varchar(190) COLLATE utf8_unicode_ci DEFAULT NULL,
  `amount` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=325 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

You can find all the Kawaii-jwt specific settings in the config/kawaii-jwt.php config file.

<?php

return [

    // these options are related to the sign-up procedure
    'sign_up' => [
        
        // this option must be set to true if you want to release a token
        // when your user successfully terminates the sign-in procedure
        'release_token' => env('SIGN_UP_RELEASE_TOKEN', false),
        
        // here you can specify some validation rules for your sign-in request
        'validation_rules' => [
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required'
        ]
    ],

    // these options are related to the login procedure
    'login' => [
        
        // here you can specify some validation rules for your login request
        'validation_rules' => [
            'email' => 'required|email',
            'password' => 'required'
        ]
    ],

    // these options are related to the password recovery procedure
    'forgot_password' => [
        
        // here you can specify some validation rules for your password recovery procedure
        'validation_rules' => [
            'email' => 'required|email'
        ]
    ],

    // these options are related to the password recovery procedure
    'reset_password' => [
        
        // this option must be set to true if you want to release a token
        // when your user successfully terminates the password reset procedure
        'release_token' => env('PASSWORD_RESET_RELEASE_TOKEN', false),
        
        // here you can specify some validation rules for your password recovery procedure
        'validation_rules' => [
            'token' => 'required',
            'email' => 'required|email',
            'password' => 'required|confirmed'
        ]
    ]

];

As I already said before, this Kawaii-jwt is based on dingo/api and tymondesigns/jwt-auth packages. So, you can find many informations about configuration here and here.

However, there are some extra options that I placed in a config/kawaii-jwt.php file:

  • sign_up.release_token: set it to true if you want your app release the token right after the sign up process;
  • reset_password.release_token: set it to true if you want your app release the token right after the password reset process;

There are also the validation rules for every action (login, sign up, recovery and reset). Feel free to customize it for your needs.

Creating Endpoints

You can create endpoints in the same way you could to with using the single dingo/api package. You can read its documentation for details. After all, that's just a boilerplate! :)

However, I added some example routes to the routes/api.php file to give you immediately an idea.

Cross Origin Resource Sharing

If you want to enable CORS for a specific route or routes group, you just have to use the cors middleware on them.

Thanks to the barryvdh/laravel-cors package, you can handle CORS easily. Just check the docs at this page for more info.

Tests

  • coming soon..

CREDITS: