Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c459259

Browse files
readme updated
1 parent ae5f29f commit c459259

File tree

4 files changed

+131
-3
lines changed

4 files changed

+131
-3
lines changed

‎README.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,132 @@
77

88
## Introduction
99

10-
A Laravel Package for easy API authentication setup with passport
10+
> A Laravel Package for easy API authentication setup with passport
1111
1212
## Installation
1313

14+
To get the latest version of Laravel Paystack, simply require it
15+
16+
1417
```bash
1518
composer require iamnotstatic/laravel-api-auth
1619
```
20+
21+
## Configuration
22+
23+
You can publish the configuration file using this command:
24+
25+
```bash
26+
php artisan vendor:publish --provider="Iamnotstatic\LaravelAPIAuth\LaravelAPIAuthServiceProvider"
27+
```
28+
29+
Migrate your database after installing the package
30+
31+
```bash
32+
php artisan migrate
33+
```
34+
35+
This command will create the encryption keys needed to generate secure access tokens. In addition, the command will create "personal access" and "password grant" clients which will be used to generate access tokens
36+
37+
```bash
38+
php artisan passport:install
39+
```
40+
41+
Next, you should call the Passport::routes method within the boot method of your AuthServiceProvider. This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens:
42+
43+
```php
44+
<?php
45+
46+
namespace App\Providers;
47+
48+
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
49+
use Illuminate\Support\Facades\Gate;
50+
use Laravel\Passport\Passport;
51+
52+
class AuthServiceProvider extends ServiceProvider
53+
{
54+
/**
55+
* The policy mappings for the application.
56+
*
57+
* @var array
58+
*/
59+
protected $policies = [
60+
'App\Model' => 'App\Policies\ModelPolicy',
61+
];
62+
63+
/**
64+
* Register any authentication / authorization services.
65+
*
66+
* @return void
67+
*/
68+
public function boot()
69+
{
70+
$this->registerPolicies();
71+
72+
Passport::routes();
73+
}
74+
}
75+
```
76+
77+
In your config/auth.php configuration file, you should set the driver option of the api authentication guard to passport. This will instruct your application to use Passport's TokenGuard when authenticating incoming API requests:
78+
79+
```php
80+
'guards' => [
81+
'web' => [
82+
'driver' => 'session',
83+
'provider' => 'users',
84+
],
85+
86+
'api' => [
87+
'driver' => 'passport',
88+
'provider' => 'users',
89+
],
90+
],
91+
```
92+
93+
In your config/auth.php configuration file, you should set the model option of the package model. This will provide a few helper methods to allow you to inspect the authenticated user's token and scopes:
94+
95+
```php
96+
'providers' => [
97+
'users' => [
98+
'driver' => 'eloquent',
99+
'model' => Iamnotstatic\LaravelAPIAuth\Models\User::class,
100+
],
101+
102+
// 'users' => [
103+
// 'driver' => 'database',
104+
// 'table' => 'users',
105+
// ],
106+
],
107+
```
108+
109+
## Usage
110+
111+
Now, we can simple test by rest client tools (Postman), So I test it and you can see below screenshots.
112+
113+
> In this api you have to set two header as listed below:
114+
115+
```bash
116+
Accept: application/json
117+
```
118+
119+
120+
121+
122+
123+
## Contributing
124+
125+
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
126+
127+
## How can I thank you?
128+
129+
Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
130+
131+
Don't forget to [follow me on twitter](https://twitter.com/iamnotstatic)!
132+
133+
Thanks!
134+
Abdulfatai Suleiman.
135+
136+
## License
137+
138+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

‎img/header.png

13.5 KB
Loading[フレーム]

‎src/Http/Controllers/Auth/LoginController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public function login (Request $request)
3333
if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
3434
$user = Auth::user();
3535
$success['token'] = $user->createToken(config('apiauth::token_key_name'))-> accessToken;
36-
return response()->json(['success' => $success], 200);
36+
return response()->json([
37+
'success' => $success,
38+
'token_type' => 'Bearer'
39+
], 200);
3740
} else {
3841
return response()->json(['error' => 'Invalid Credentails'], 401);
3942
}

‎src/Http/Controllers/Auth/RegisterController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function register(Request $request)
4040
$user->save();
4141
$success['token'] = $user->createToken(config('apiauth::token_key_name'))-> accessToken;
4242

43-
return response()->json(['success' => $success], 201);
43+
return response()->json([
44+
'success' => $success,
45+
'token_type' => 'Bearer'
46+
], 201);
4447

4548
}
4649

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /