Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dangdungcntt/laravel-passport-iam
https://github.com/dangdungcntt/laravel-passport-iam
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dangdungcntt/laravel-passport-iam
- Owner: dangdungcntt
- License: mit
- Created: 2019-01-10T14:35:37.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-13T04:12:23.000Z (almost 6 years ago)
- Last Synced: 2024-04-14T07:50:00.477Z (9 months ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Integrate with Passport IAM
## Installation
You can install the package via composer:
```bash
composer require nddcoder/laravel-passport-iam
```You can optionally publish the config file with:
```bash
php artisan vendor:publish --provider="Nddcoder\PassportIAM\IAMServiceProvider" --tag="config"
```This is the contents of the published config file:
```php
return [
'base_url' => env('PASSPORT_IAM_BASE_URL'),
'path' => [
'oauth_token' => 'oauth/token',
'user' => 'api/user'
],
'client_id' => env('PASSPORT_IAM_CLIENT_ID'),
'client_secret' => env('PASSPORT_IAM_CLIENT_SECRET'),
'common_fields' => explode(',', env('PASSPORT_IAM_COMMON_FIELDS')),
'mapping_field' => [
'iam' => 'uuid',
'local' => 'uuid'
]
];
```## Config
#### Update config/auth.php
``` php
return [
//...
'guards' => [
//...'api' => [
'driver' => 'access_token',
'provider' => 'tokens',
],
//...
],
//...
'providers' => [
//...'tokens' => [
'driver' => 'token',
'model' => App\User::class,
]//...
]
];
```#### Fill info in .env
```
PASSPORT_IAM_BASE_URL=https://iam.domain.com
PASSPORT_IAM_CLIENT_ID=
PASSPORT_IAM_CLIENT_SECRET=
```## Usage
#### Login using email/password
```php
use Nddcoder\PassportIAM\Services\IAMServiceInterface;$reponse = app(IAMServiceInterface::class)->login(['email' => '[email protected]', 'passord' => 'secret']);
/*
{
"token_type": "Bearer",
"expires_in": 2592000,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsI...",
"refresh_token": "def50200ffa17b51e9e46117..."
}
*/
```#### Valdiate token in request use middleware `auth:api`
```php
Route::group(['middleware' => ['auth:api']], function () {
Route::get('/me', function(Request $request) {
return $request->user();
})
});
```## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.