Giter Club home page Giter Club logo

remote-user's Introduction

Remote User Packag

Latest Version on Packagist Total Downloads GitHub Actions

This package simplifies integration with an IAM server within a microservices architecture by fetching the logged-in remote user's information. It ensures security by returning only one record per authorized user. While primarily designed for use with IAM servers, it is also compatible with other OAuth2 servers. The user data is expected in a simple array format from the user endpoint, with uuid as the mandatory field.

Requirements

  • Laravel Sanctum
  • User model should utilize the AsRemoteUser trait and implement the RemoteUser contract.

Installation

Install the package via Composer:

composer require kwidoo/remote-user

Optionally, publish the configuration file:

php artisan vendor:publish --tag=remote-user-config

Configuration

Add the following IAM server's OAuth2 credentials to your .env file:

IAM_SERVER_CLIENT_ID=your-client-id
IAM_SERVER_CLIENT_SECRET=your-client-secret
IAM_SERVER_URL=your-iam-server-url

Ensure your auth.php file is configured with the appropriate guards and providers to use with this package:

'guards' => [
    'api' => [
        'driver' => 'sanctum',
        'provider' => 'remote_users',
    ],
],
'providers' => [
    'remote_users' => [
        'driver' => 'remote',
        'model' => App\Models\User::class, // or you model
    ],
],

These settings configure Laravel to use Sanctum with the remote user model, ensuring proper authentication handling through the IAM server.

You can specify an alternative user model in the configuration file:

    'user_class' => App\Models\User::class  // or your model

Usage

This package facilitates the following workflow in conjunction with an IAM server and local Laravel Sanctum:

  1. The frontend obtains a password grant and opaque token from the IAM server.
  2. The frontend sends the opaque token to this package.
  3. The package obtains a client credentials grant from the IAM server.
  4. By using the opaque token along with the access token from step 3, it fetches the remote user from the IAM server.
  5. If the user is successfully fetched, it provides a Sanctum token to the frontend.

Obtaining Sanctum Token

To obtain a Sanctum token, make a GET request to the /sanctum/token endpoint. You can change the route as needed:

Route::get('/sanctum/token', RemoteUserController::class . '@token');

Troubleshooting

If you encounter issues accessing the /sanctum/token route, use:

php artisan route:list

to verify the exact route.

Testing

Run tests using:

composer test

Changelog

For recent changes, please refer to the CHANGELOG.

Contributing

For contribution guidelines, please see CONTRIBUTING.

Security

For security-related issues, please contact [email protected] directly rather than using the public issue tracker.

Credits

License

This package is licensed under the MIT License. See the License File for more details.

Additional Information

This package was developed using the Laravel Package Boilerplate.

remote-user's People

Watchers

Oleg Pashkovsky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.