2022-08-12 07:56:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2022-09-08 16:12:02 +00:00
|
|
|
use App\Models\AccessToken;
|
|
|
|
use App\Models\Module\Module;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
2022-08-12 07:56:56 +00:00
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
2022-09-08 16:12:02 +00:00
|
|
|
* Register any application services.
|
2022-08-12 07:56:56 +00:00
|
|
|
*
|
2022-09-08 16:12:02 +00:00
|
|
|
* @return void
|
2022-08-12 07:56:56 +00:00
|
|
|
*/
|
2022-09-08 16:12:02 +00:00
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
2022-08-12 07:56:56 +00:00
|
|
|
|
|
|
|
/**
|
2022-09-08 16:12:02 +00:00
|
|
|
* Boot the authentication services for the application.
|
2022-08-12 07:56:56 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2022-09-08 16:12:02 +00:00
|
|
|
// Here you may define how you wish users to be authenticated for your Lumen
|
|
|
|
// application. The callback which receives the incoming request instance
|
|
|
|
// should return either a User instance or null. You're free to obtain
|
|
|
|
// the User instance via an API token or any other method necessary.
|
2022-08-12 07:56:56 +00:00
|
|
|
|
2022-09-08 16:12:02 +00:00
|
|
|
|
|
|
|
// api guard and remote
|
|
|
|
|
|
|
|
$this->app['auth']->viaRequest('api', function ($request) {
|
2022-09-08 17:47:03 +00:00
|
|
|
// if ($request->input('api_token')) {
|
|
|
|
// return AccessToken::where('token', $request->input('api_token'))->with('user')->first()->user ?? null;
|
|
|
|
// }
|
2022-09-08 16:12:02 +00:00
|
|
|
// bearerToken
|
|
|
|
$bearerToken = $request->bearerToken();
|
|
|
|
|
|
|
|
|
|
|
|
return AccessToken::where('token', $bearerToken)->with('user')->first()->user ?? null;
|
|
|
|
|
|
|
|
// if ($request->input('api_token')) {
|
|
|
|
// return User::where('api_token', $request->input('api_token'))->first();
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->app['auth']->viaRequest('remote', function ($request) {
|
|
|
|
|
2022-09-08 17:47:03 +00:00
|
|
|
// if ($request->input('api_token')) {
|
|
|
|
// return Module::where('api_token', $request->input('api_token'))->first();
|
|
|
|
// }
|
2022-09-08 16:12:02 +00:00
|
|
|
// bearerToken
|
|
|
|
$bearerToken = $request->bearerToken();
|
|
|
|
|
|
|
|
|
|
|
|
return Module::where('token', $bearerToken)->first() ?? null;
|
|
|
|
|
|
|
|
// if ($request->input('api_token')) {
|
|
|
|
// return User::where('api_token', $request->input('api_token'))->first();
|
|
|
|
// }
|
|
|
|
});
|
2022-08-12 07:56:56 +00:00
|
|
|
}
|
|
|
|
}
|