2017 © Pedro Peláez
 

library mesa-gold-bar

A library that provides remote user identification from oauth2 access tokens.

image

sympla/mesa-gold-bar

A library that provides remote user identification from oauth2 access tokens.

  • Wednesday, November 29, 2017
  • by naroga
  • Repository
  • 0 Watchers
  • 3 Stars
  • 2,180 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 31 Versions
  • 18 % Grown

The README.md

sympla/mesa-gold-bar

Mesa Gold is a resort and bar located within the Westworld Mesa Hub. It is used by the Guests to relax at the end of their visit to the Park., (*1)

This library helps identifying users by their access tokens., (*2)

Installation

Install the package using composer:, (*3)

$ composer require sympla/mesa-gold-bar ~3.0

That's it., (*4)

Usage

The authenticator gets two parameters in its constructor: a Guzzle client and an authentication endpoint, as a string. Once built, you can identify an user using either the raw token or a PSR-7 request object:, (*5)

<?php

require_once "vendor/autoload.php";

use Sympla\Auth\OAuth2RemoteAuthentication;

$authenticator = new OAuth2RemoteAuthentication(
    new GuzzleHttp\Client,
     'https://example.com/api/whoami'
);

//Gets the user from the request object
$request = Request::createFromGlobals(); // hydrates the psr-7 request object
$user = $authenticator->getUserFromRequest($request);
// Or, alternatively, gets the user from the token directly:
$token = explode(" ", $_SERVER['HTTP_AUTHORIZATION'])[1];
$user = $authenticator->getUserFromToken($token);

var_dump($user); // dumps information fetched from the endpoint server about the user.

Middleware

This library now also has a SlimMiddleware for retrieving user credentials., (*6)

Just add the middleware:, (*7)

<?php
#middleware.php
$app->add(new \Sympla\Auth\Middleware\SlimMiddleware(
    new \GuzzleHttp\Client,
    $app->getContainer(),
    [
        'protected' => ['/^\/admin\//'], //This is a regex for the protected URIs
        'authentication_server' => getenv('USER_INFO_ENDPOINT') //This is where the middleware
                                                                //should try to fetch the user info from
    ]
));

Then, from any of the protected routes, you can simply fetch the user object from your DIC:, (*8)

<?php
#routes.php
$app->get('/admin', function ($request, $response, $args) {
    $user = $this->get('user');
    var_dump($user);
});

Using with Laravel

After install it, register the service provider into your Laravel application into config/app.php:, (*9)

Sympla\Auth\Laravel\ServiceProvider::class

Then, publish the configuration:, (*10)

$ php artisan vendor:publish --provider="Sympla\Auth\Laravel\ServiceProvider"

Once your application is configured, go to config/auth.php and change the guard section:, (*11)

     'guards' => [
         'api' => [
             'driver' => 'token',
             'provider' => 'oauth',
         ],
     ],

And the providers section:, (*12)

    'providers' => [
        'oauth' => [
            'driver' => 'oauth'
            'model' => App\User::class,
        ],
    ],

Then, activate the auth:api as a middleware for your api., (*13)

Using with Lumen

After install it, register the service provider, route middleware, Hash facade and enable eloquent into your Lumen application into bootstrap/app.php:, (*14)

//Service provider
$app->register(Sympla\Auth\Lumen\ServiceProvider::class);

// Route middleware
$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

//Hash facade
$app->withFacades(true, ['Illuminate\Support\Facades\Hash' => 'Hash']);

//Enable eloquent
$app->withEloquent();

After register the service provider, install the package for publish in Lumen application, (*15)

$ composer require laravelista/lumen-vendor-publish

Then, publish the configuration:, (*16)

$ php artisan vendor:publish --provider="Sympla\Auth\Lumen\ServiceProvider"

Once your application is configured, go to config/auth.php, if the file does not exist just create it, and change/create the guard section:, (*17)

     'guards' => [
         'api' => [
             'driver' => 'token',
             'provider' => 'oauth',
         ],
     ],

And the providers section:, (*18)

    'providers' => [
        'oauth' => [
            'driver' => 'oauth'
            'model' => App\User::class,
        ],
    ],

Contact

Pedro Igor pedro.igor@sympla.com.br, (*19)

License

This project is distributed under the MIT License. Check [LICENSE][LICENSE.md] for more information., (*20)

The Versions

29/11 2017

dev-master

9999999-dev

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

29/11 2017

3.2.3

3.2.3.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

29/11 2017

dev-fix/remove-oauth-index-from-token

dev-fix/remove-oauth-index-from-token

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

27/11 2017

3.2.2

3.2.2.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

06/11 2017

3.2.1

3.2.1.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

06/11 2017

dev-fix/checkIfPublicKeyPathExists

dev-fix/checkIfPublicKeyPathExists

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

24/10 2017

3.2.0

3.2.0.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

24/10 2017

dev-feature/addJWTSupport

dev-feature/addJWTSupport

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

27/09 2017

3.1.9

3.1.9.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

27/09 2017

dev-fix/checkProvider

dev-fix/checkProvider

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

27/09 2017

3.1.8

3.1.8.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

27/09 2017

dev-feature/ClientProviderAndDomainCheck

dev-feature/ClientProviderAndDomainCheck

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

17/08 2017

3.1.7

3.1.7.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

17/08 2017

3.1.6

3.1.6.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

17/08 2017

3.1.5

3.1.5.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

17/07 2017

3.1.4

3.1.4.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

17/07 2017

dev-feature/add-auth-method

dev-feature/add-auth-method

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

23/05 2017

3.1.3

3.1.3.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

23/05 2017

dev-optional-params

dev-optional-params

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

16/05 2017

3.1.2

3.1.2.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

15/05 2017

3.1.1

3.1.1.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

15/05 2017

dev-fix-not-authorized-response

dev-fix-not-authorized-response

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

11/05 2017

3.1.0

3.1.0.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

19/04 2017

3.0.1

3.0.1.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

23/02 2017

3.0

3.0.0.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

23/02 2017

dev-dev

dev-dev

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

10/02 2017

1.0.3

1.0.3.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

10/02 2017

2.0

2.0.0.0

A library that provides remote user identification from oauth2 access tokens.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pedro Cordeiro

23/12 2016

1.0.2

1.0.2.0

A library that provides remote user authentication under OAuth2.

  Sources   Download

proprietary

The Requires

 

by Pedro Cordeiro

22/12 2016

1.0.1

1.0.1.0

A library that provides remote user authentication under OAuth2.

  Sources   Download

proprietary

The Requires

 

by Pedro Cordeiro

16/12 2016

1.0

1.0.0.0

A library that provides remote user authentication under OAuth2.

  Sources   Download

proprietary

The Requires

 

by Pedro Cordeiro