bashofmann

added readme and example

OAuth 2.0 client library PHP
============================
This PHP library helps you to implement an OAuth 2.0 client.
It uses the draft 10 of the current OAuth 2.0 specification [1]
Currently only the web_server flow is and the core response_type is supported.
Example
-------
An example implementation is available in example.php
License
-------
Copyright (c) 2010 VZnet Netzwerke Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[1]: http://tools.ietf.org/html/draft-ietf-oauth-v2-10
\ No newline at end of file
... ...
<?php
require_once 'oauth2.php';
// configuration of client credentials
$client = new OAuth2_Client(
'CLIENT_ID',
'CLIENT_SECRET',
'CALLBACK_URL');
// configuration of service
$configuration = new OAuth2_Service_Configuration(
'AUTHORIZE_ENDPOINT',
'ACCESS_TOKEN_ENDPOINT');
// storage class for access token, just extend OAuth2_DataStore_Abstract for
// your own implementation
$dataStore = new OAuth2_DataStore_Session();
$scope = null;
$service = new OAuth2_Service($client, $configuration, $dataStore, $scope);
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'authorize':
// redirects to authorize endpoint
$service->authorize();
break;
case 'requestApi':
// calls api endpoint with access token
echo $service->callApiEndpoint('API_ENDPOINT');
break;
}
}
if (isset($_GET['code'])) {
// retrieve access token from endpoint
$service->getAccessToken();
}
$token = $dataStore->retrieveAccessToken();
?>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
Consumer Key: <input type="text" id="consumer-key" value="<?= $client->getClientKey() ?>" /><br />
Consumer Secret: <input type="text" id="consumer-secret" value="<?= $client->getClientSecret() ?>" /><br />
Access Token: <input type="text" id="access-token" value="<?= $token->getAccessToken() ?>" /><br />
Refresh Token: <input type="text" id="refresh-token" value="<?= $token->getRefreshToken() ?>" /><br />
LifeTime: <input type="text" id="lifetime" value="<?= $token->getLifeTime() ?>" /><br />
<br />
<a href="javascript:;" id="authorize">authorize</a><br />
<br />
<a href="javascript:;" id="request-api">request API</a><br />
<script type="text/javascript">
$('#authorize').click(function() {
window.location.href = 'index.php?action=authorize';
});
$('#request-api').click(function() {
window.location.href = 'index.php?action=requestApi';
});
</script>
</body>
</html>
\ No newline at end of file
... ...