2017 © Pedro Peláez
 

library oauth2-marvin

Marvin (42) OAuth 2.0 Client Provider for League OAuth2-Client

image

bde42/oauth2-marvin

Marvin (42) OAuth 2.0 Client Provider for League OAuth2-Client

  • Thursday, November 5, 2015
  • by dren
  • Repository
  • 2 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Marvin Provider for OAuth 2.0 Client

This package provides 42 OAuth 2.0 support for the PHP League's OAuth 2.0 Client., (*1)

Installation

To install, use composer:, (*2)

composer require bde42/oauth2-marvin

Usage

Usage is the same as The League's OAuth client, using \BDE42\OAuth2\Client\Provider\Marvin as the provider., (*3)

Authorization Code Flow

if (session('current_user') == null)
{
    $provider = new \BDE42\OAuth2\Client\Provider\Marvin([
        'clientId'          => 'your_client_id',
        'clientSecret'      => 'your_secret',
        'redirectUri'       => 'https://uri/to/redirect'
    ]);

    // If we don't have an authorization code then get one
    if (!isset($_GET['code'])) {
        $authUrl = $provider->getAuthorizationUrl(/*options*/);
        session(['oauth2state' => $provider->getState()]);
        return redirect($authUrl);

    // Check given state against previously stored one to mitigate CSRF attack
    } else if (empty($_GET['state']) || $_GET['state'] !== session('oauth2state'))
    {
        session(['oauth2state' => null]);
        exit('Invalid state');
    }

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    // Try to get an access token (using the authorization code grant)
    try {
        $user = $provider->getResourceOwner($token);
    } catch (Exception $e) {
        exit('Oh dear...');
    }

    session(['current_user' => $user->getUserInfos()]); //Basic informations (uid, email, name and login)
    //$user->toArray() //Get all user informations whose you have the access authorization

    print_r ("NEW USER : ".json_encode(session('current_user')));
} else {
    print_r ("REGISTERED USER : ".json_encode(session('current_user')));
}

Testing

bash $ ./vendor/bin/phpunit, (*4)

Contributing

Please see CONTRIBUTING for details., (*5)

Credits

License

The MIT License (MIT). Please see License File for more information., (*6)

The Versions

05/11 2015

dev-master

9999999-dev

Marvin (42) OAuth 2.0 Client Provider for League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Franck Kalb

authorization oauth client oauth2 authorisation marvin 42

05/11 2015

1.0.1

1.0.1.0

Marvin (42) OAuth 2.0 Client Provider for League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Franck Kalb

authorization oauth client oauth2 authorisation marvin 42

04/10 2015

1.0

1.0.0.0

Marvin (42) OAuth 2.0 Client Provider for League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Franck Kalb

authorization oauth client oauth2 authorisation marvin 42