2017 © Pedro Peláez
 

library oauth2

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

image

evert/oauth2

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

  • Tuesday, July 16, 2013
  • by evert
  • Repository
  • 2 Watchers
  • 3 Stars
  • 8,639 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 156 Forks
  • 1 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

Simple OAuth2 client for PHP

Author & Contact

Charron Pierrick - pierrick@webstart.fr, (*1)

Berejeb Anis - anis.berejeb@gmail.com, (*2)

Documentation & Download

Latest version is available on github at : - https://github.com/adoy/PHP-OAuth2, (*3)

Documentation can be found on : - https://github.com/adoy/PHP-OAuth2, (*4)

License

This Code is released under the GNU LGPL, (*5)

Please do not change the header of the file(s)., (*6)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version., (*7)

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE., (*8)

See the GNU Lesser General Public License for more details., (*9)

Usage instructions

<?php

include 'vendor/autoload.php';

$clientId = 'your client id';
$clientSecret = 'your client secret';

$redirectUri = 'http://url/of/this.php';
$authorizationEndPoint = 'https://graph.facebook.com/oauth/authorize';
$tokenEndPoint = 'https://graph.facebook.com/oauth/access_token';

$client = new OAuth2\Client($clientId, $clientSecret);
if (!isset($_GET['code']))
{
    $auth_url = $client->getAuthenticationUrl($authorizationEndPoint, $redirectUri);
    header('Location: ' . $auth_url);
    die('Redirect');
}
else
{
    $params = array('code' => $_GET['code'], 'redirect_uri' => $redirectUri);
    $response = $client->getAccessToken($tokenEndPoint, 'authorization_code', $params);
    parse_str($response['result'], $info);
    $client->setAccessToken($info['access_token']);
    $response = $client->fetch('https://graph.facebook.com/me');
    var_dump($response, $response['result']);
}

Adding a new grand type

Simply write a new class in the namespace OAuth2\GrantType. You can place the class file under GrantType. Here is an example :, (*10)

<?php

namespace OAuth2\GrantType;

/**
 * MyCustomGrantType Grant Type
 */
class MyCustomGrantType implements IGrantType
{
    /**
     * Defines the Grant Type
     *
     * @var string  Defaults to 'my_custom_grant_type'.
     */
    const GRANT_TYPE = 'my_custom_grant_type';

    /**
     * Adds a specific Handling of the parameters
     *
     * @return array of Specific parameters to be sent.
     * @param  mixed  $parameters the parameters array (passed by reference)
     */
    public function validateParameters(&$parameters)
    {
        if (!isset($parameters['first_mandatory_parameter']))
        {
            throw new \Exception('The \'first_mandatory_parameter\' parameter must be defined for the Password grant type');
        }
        elseif (!isset($parameters['second_mandatory_parameter']))
        {
            throw new \Exception('The \'seconde_mandatory_parameter\' parameter must be defined for the Password grant type');
        }
    }
}

Call the OAuth client getAccessToken with the grantType you defined in the GRANT_TYPE constant, as follows:, (*11)

$response = $client->getAccessToken(TOKEN_ENDPOINT, 'my_custom_grant_type', $params);

The Versions

16/07 2013

dev-master

9999999-dev

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

  Sources   Download

The Requires

  • php >=5.3.0

 

by Pierrick Charron
by Berejeb Anis

16/07 2013

1.2.0

1.2.0.0

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

  Sources   Download

The Requires

  • php >=5.3.0

 

by Pierrick Charron
by Berejeb Anis

16/07 2013

dev-no_http_method_constants

dev-no_http_method_constants

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

  Sources   Download

by Pierrick Charron
by Berejeb Anis

15/07 2013

dev-readme-fixes

dev-readme-fixes

Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)

  Sources   Download

by Pierrick Charron
by Berejeb Anis