Code Monkey home page Code Monkey logo

laravel-api-auth's Introduction

api-auth

Software License GitHub issues Total Downloads Build Status

Install

composer require bitfumes/api-auth

Steps to follow

Steps 1

  1. Add Contract hasApiAuth and JWTSubject to your authenticatable model like shown below:
  2. Add ApiAuth trait to your user model.
use Bitfumes\ApiAuth\Traits\ApiAuth;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Bitfumes\ApiAuth\Contract\HasApiAuth;

class User extends Authenticatable implements HasApiAuth, JWTSubject
{
    use Notifiable, ApiAuth;
    ...
}

Step 2

Configure your config/auth.php file to update guard details

  • Update default guard to api
'defaults' => [
        'guard'     => 'api',
        ...
    ],
  • Update api guard to 'jwt'
'guards' => [
        ... ,

        'api' => [
            'driver'   => 'jwt',
            ...
        ],
    ],

Step 3

Add new accessor to your authenticatable model

public function setPasswordAttribute($value)
{
    $this->attributes['password'] = bcrypt($value);
}

Step 4

Now publish two new migrations

  1. To add avatar field to your use model.
  2. To add social login profile.
php artisan vendor:publish --tag=api-auth:migrations

Step 5

After getting migrations in your laravel application, its time to have these tables in your database.

php artisan migrate

Step 6

Because every user need to verify its email and to send email we are going to use laravel queue.

Now add queue driver on your .env file

That's it, now enjoy api auth with JWT

QUEUE_DRIVER=database

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

laravel-api-auth's People

Contributors

sarthaksavvy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.