Skip to content

Commit eb0977e

Browse files
committed
PHP-OAuth2-8b39849eba97b439940bb92a70d820a8235a183d , pre-built with composer
1 parent 6b5247e commit eb0977e

18 files changed

+1418
-2
lines changed

README.md

+117-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,117 @@
1-
# php_oauth2
2-
PHP Oauth Library, pre-built with composer
1+
___________________________________
2+
3+
Light PHP wrapper for the OAuth 2.0
4+
___________________________________
5+
6+
7+
AUTHOR & CONTACT
8+
================
9+
10+
Charron Pierrick
11+
12+
13+
Berejeb Anis
14+
15+
16+
17+
DOCUMENTATION & DOWNLOAD
18+
========================
19+
20+
Latest version is available on github at :
21+
- https://github.com/adoy/PHP-OAuth2
22+
23+
Documentation can be found on :
24+
- https://github.com/adoy/PHP-OAuth2
25+
26+
27+
LICENSE
28+
=======
29+
30+
This Code is released under the GNU LGPL
31+
32+
Please do not change the header of the file(s).
33+
34+
This library is free software; you can redistribute it and/or modify it
35+
under the terms of the GNU Lesser General Public License as published
36+
by the Free Software Foundation; either version 2 of the License, or
37+
(at your option) any later version.
38+
39+
This library is distributed in the hope that it will be useful, but
40+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
41+
or FITNESS FOR A PARTICULAR PURPOSE.
42+
43+
See the GNU Lesser General Public License for more details.
44+
45+
46+
How can I use it ?
47+
==================
48+
49+
require('Client.php');
50+
require('GrantType/IGrantType.php');
51+
require('GrantType/AuthorizationCode.php');
52+
53+
const CLIENT_ID = 'your client id';
54+
const CLIENT_SECRET = 'your client secret';
55+
56+
const REDIRECT_URI = 'http://url/of/this.php';
57+
const AUTHORIZATION_ENDPOINT = 'https://graph.facebook.com/oauth/authorize';
58+
const TOKEN_ENDPOINT = 'https://graph.facebook.com/oauth/access_token';
59+
60+
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
61+
if (!isset($_GET['code']))
62+
{
63+
$auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
64+
header('Location: ' . $auth_url);
65+
die('Redirect');
66+
}
67+
else
68+
{
69+
$params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
70+
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
71+
parse_str($response['result'], $info);
72+
$client->setAccessToken($info['access_token']);
73+
$response = $client->fetch('https://graph.facebook.com/me');
74+
var_dump($response, $response['result']);
75+
}
76+
77+
How can I add a new Grant Type ?
78+
================================
79+
Simply write a new class in the namespace OAuth2\GrantType. You can place the class file under GrantType.
80+
Here is an example :
81+
82+
namespace OAuth2\GrantType;
83+
84+
/**
85+
* MyCustomGrantType Grant Type
86+
*/
87+
class MyCustomGrantType implements IGrantType
88+
{
89+
/**
90+
* Defines the Grant Type
91+
*
92+
* @var string Defaults to 'my_custom_grant_type'.
93+
*/
94+
const GRANT_TYPE = 'my_custom_grant_type';
95+
96+
/**
97+
* Adds a specific Handling of the parameters
98+
*
99+
* @return array of Specific parameters to be sent.
100+
* @param mixed $parameters the parameters array (passed by reference)
101+
*/
102+
public function validateParameters(&$parameters)
103+
{
104+
if (!isset($parameters['first_mandatory_parameter']))
105+
{
106+
throw new \Exception('The \'first_mandatory_parameter\' parameter must be defined for the Password grant type');
107+
}
108+
elseif (!isset($parameters['second_mandatory_parameter']))
109+
{
110+
throw new \Exception('The \'seconde_mandatory_parameter\' parameter must be defined for the Password grant type');
111+
}
112+
}
113+
}
114+
115+
call the OAuth client getAccessToken with the grantType you defined in the GRANT_TYPE constant, As following :
116+
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'my_custom_grant_type', $params);
117+

composer.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "adoy/oauth2",
3+
"description": "Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)",
4+
"license": "LGPL-2.1",
5+
"authors": [
6+
{
7+
"name": "Charron Pierrick",
8+
"email": "[email protected]"
9+
},
10+
{
11+
"name": "Berejeb Anis",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"require": {
16+
"php": ">=5.3.0"
17+
},
18+
"autoload": {
19+
"psr-0": {"OAuth2": "src/"}
20+
}
21+
}

composer.lock

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)