/LaravelAuthApi

Backend for an api to authenticate users with local and social authentication

Primary LanguagePHPMIT LicenseMIT

Laravel Auth Api

Backend for an api to authenticate users, including both local and social authentication.

It uses Laravel Passport for API authentication and tokens, and Laravel Socialite for social authentication. These packages are automatically included.

In the future, this package will work in conjunction with a front-end component pack.

Installation

Via Composer

$ composer require jijoel/laravel-auth-api

Configuration

To scaffold the authentication controllers:

$ php artisan make:api-auth

To automatically generate routes, include this in routes/api.php:

ApiAuth::routes();
ApiAuth::socialRoutes();      // oauth routes

ApiAuth::routes(['social']);  // include oauth routes

Add a relationship to linked social accounts to your user model:

public function linkedSocialAccounts()
{
    return $this->hasMany('Jijoel\AuthApi\LinkedSocialAccount');
}

Usage

The ApiAuth::routes() method, above, will create these endpoints:

Methods Route Route Name
POST api/login login
POST api/logout logout
GET HEAD api/oauth/{driver}
GET HEAD api/oauth/{driver}/callback
POST api/password/email password.email
POST api/password/reset password.reset
POST api/register register

It also sets up an @config blade compiler directive, so you can load application-specific configuration into your javascript. By default, it will include this configuration:

'appName' => config('app.name'),
'locale' => $locale = app()->getLocale(),
'locales' => config('app.locales'),

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ phpunit

Contributing

Please see contributing.md for details and a todolist.

Security

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

Credits

https://medium.com/@hivokas/api-authentication-via-social-networks-for-your-laravel-application-d81cfc185e60

License

license. Please see the license file for more information.