https://github.com/bitfumes/laravel-api-auth
create api auth using JWT in just 1 minute
https://github.com/bitfumes/laravel-api-auth
Last synced: about 2 months ago
JSON representation
create api auth using JWT in just 1 minute
- Host: GitHub
- URL: https://github.com/bitfumes/laravel-api-auth
- Owner: bitfumes
- License: mit
- Created: 2019-07-27T11:37:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-21T06:07:02.000Z (about 2 years ago)
- Last Synced: 2024-04-24T12:26:57.544Z (about 1 year ago)
- Language: PHP
- Size: 58.6 KB
- Stars: 6
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# api-auth
[](LICENSE.md)
[](https://github.com/bitfumes/laravel-api-auth/issues)
[](https://packagist.org/packages/bitfumes/api-auth)
[](https://travis-ci.org/bitfumes/laravel-api-auth)# 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.```php
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
```php
'defaults' => [
'guard' => 'api',
...
],
```- Update api guard to 'jwt'
```php
'guards' => [
... ,'api' => [
'driver' => 'jwt',
...
],
],
```## Step 3
Add new accessor to your authenticatable model
```php
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.```bash
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.
```bash
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:
```bash
vendor/bin/phpunit
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) 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](/LICENSE.md) for more information.