Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)
PHP
Branch: master
Pull request Compare This branch is 57 commits behind adoy:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README
client.php

README

                    ___________________________________
  
                    Light PHP wrapper for the OAuth 2.0
                    ___________________________________


AUTHOR & CONTACT
================

Charron Pierrick
    - pierrick@webstart.fr

    
DOCUMENTATION & DOWNLOAD
========================

Latest version is available on github at :
    - https://github.com/adoy/PHP-OAuth2

Documentation can be found on : 
    - https://github.com/adoy/PHP-OAuth2


LICENSE
=======

This Code is released under the GNU LGPL

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

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.

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.

See the GNU Lesser General Public License for more details.


How can I use it ?
==================

require('client.php');

const CLIENT_ID     = 'your client id';
const CLIENT_SECRET = 'your client secret';

const REDIRECT_URI           = 'http://url/of/this.php';
const AUTHORIZATION_ENDPOINT = 'https://graph.facebook.com/oauth/authorize';
const TOKEN_ENDPOINT         = 'https://graph.facebook.com/oauth/access_token';

$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code']))
{
    $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
    header('Location: ' . $auth_url);
    die('Redirect');
}
else
{
    $params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
    $response = $client->getAccessToken(TOKEN_ENDPOINT, OAuth2\Client::GRANT_TYPE_AUTH_CODE, $params);
    $client->setAccessToken($response['result']['access_token']);
    $response = $client->fetch('https://graph.facebook.com/me');
    var_dump($response, $response['result']);
}
Something went wrong with that request. Please try again.