alexgithubber/santanu-lumen-mongodb-oauth

OAuth API Authorization based on Lumen Framework and MongoDB

dev-master 2019-12-09 22:07 UTC

This package is not auto-updated.

Last update: 2023-06-06 14:53:38 UTC


README

This fork was made with the purpose of simplifying sending information to the oauth's server config (ex. token lifetime) and changed the default grant type to 'client_credentials', the 'password' grant type is unavailable at the moment.

OAuth Library for Lumen & MongoDB

Package for creating oauthable authorization based on Lumen Framework and MongoDB.

Package Installations

  • Add "santanu/lumen-mongodb-oauth": "*" in your lumen project, then run composer update.
  • Copy all migration files from database/migrations to project's db migration directory.
  • Run php artisan migrate from project's root directory.
  • Add 'client_id' and 'client_secret' value in the clients collection.
  • Need to copy config files from src/config to project's config directory.
  • Now change User model name and path in oauth.php config file.

Configure Application

  • Model User should be implement Santanu\Lumen_Oauth\Interfaces\Oauthable
  • Add trait for model User Santanu\Lumen_Oauth\Traits\Oauthable
  • Add service provider Santanu\Lumen_Oauth\Providers\ServiceProvider
  • In routes/web.php add following lines for Oauth service,
$app->group(['prefix' => 'oauth'], function() use ($app)
{
    $app->post('access', function() use($app) {
		return $app->make('oauth.routes')->accessToken();
    });
	$app->post('refresh', function() use($app) {
		return $app->make('oauth.routes')->refreshToken();
    });
});

In this fork you may send the server's config as an array param to the accessToken and refreshToken methods, example:

    $app->post('access', function() use($app) {
		return $app->make('oauth.routes')->accessToken(['allow_implicit' => true, 'access_lifetime' => 7200]);
    });
  • In routes add 'oauth' as a middleware in service routes.

Authorization Service

  • POST application-url/oauth/access Params: grant_type(password), client_id, client_secret, username, password Response: access_token, expires_in, token_type, scope, refresh_token
  • POST application-url/oauth/refresh Params: grant_type(refresh_token), client_id, client_secret, refresh-token Response: access_token, expires_in, token_type, scope, refresh_token
  • Send header in all API requests: Authorization: Bearer access_token

Important Information