Last active
February 21, 2021 09:05
-
-
Save ssi-anik/9258b453b1bb4bef07c8a01b56182a96 to your computer and use it in GitHub Desktop.
snippet 1 from https://github.com/ssi-anik/laravel-custom-auth for medium article - https://medium.com/@sirajul.anik/laravel-api-authenticate-user-with-custom-driver-different-table-using-auth-middleware-fa2cabec2d61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers; | |
| use App\Extensions\AccessTokenGuard; | |
| use App\Extensions\TokenToUserProvider; | |
| use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
| use Illuminate\Support\Facades\Auth; | |
| class AuthServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * The policy mappings for the application. | |
| * @var array | |
| */ | |
| protected $policies = [ | |
| 'App\Model' => 'App\Policies\ModelPolicy', | |
| ]; | |
| /** | |
| * Register any authentication / authorization services. | |
| * @return void | |
| */ | |
| public function boot () { | |
| $this->registerPolicies(); | |
| Auth::extend('access_token', function ($app, $name, array $config) { | |
| // automatically build the DI, put it as reference | |
| $userProvider = app(TokenToUserProvider::class); | |
| $request = app('request'); | |
| return new AccessTokenGuard($userProvider, $request, $config); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment