Package Data | |
---|---|
Maintainer Username: | ecmXperts |
Maintainer Contact: | m.vels@ecmxperts.nl (Mark Vels) |
Package Create Date: | 2020-11-23 |
Package Last Update: | 2021-10-13 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-31 03:08:36 |
Package Statistics | |
---|---|
Total Downloads: | 185 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Lumen Oauth2 provides a simple API to authenticate your Lumen api with an Openid/Oauth2 server.
Run composer require ecmxperts/lumenoauth2 0.*
In your .env
add the following Environment Variable
IDENTITY_URL=openid/oauth2 server address
In your app\Providers\AuthServiceProvider.php
inside the boot method add the following lines
$this->app['auth']->viaRequest('api', function ($request) {
if (($token = $request->bearerToken()) != null) {
try {
return LumenOAuth2::setProviderUrl(env('IDENTITY_URL'))
->setAudience('expected audience')
->authenticate($token);
} catch (LumenOauth2Exception $e) {
Log::error($e, ['exception' => $e]);
}
}
});
See Lumen Authentication for the rest on Authentication
The following methods can be used to access the authenticated user properties:
$userGuid = Auth::user()->guid();
$userGuid = $request->user()->guid();
$firstname = Auth::user()->firstname();
$firstname = $request->user()->firstname();
$surname = Auth::user()->surname();
$surname = $request->user()->surname();
$fullname = Auth::user()->fullname();
$fullname = $request->user()->fullname();
$tenant = Auth::user()->tenant();
$tenant = $request->user()->tenant();