Merge commit '847b222bd4021267176431c6d8f14de15624fc56' as 'phpoauthlib'
commit
4e1ba47a47
@ -0,0 +1,5 @@
|
||||
.idea
|
||||
vendor
|
||||
.DS_Store
|
||||
composer.lock
|
||||
examples/init.php
|
@ -0,0 +1,37 @@
|
||||
before_commands:
|
||||
- "composer install --dev --prefer-source"
|
||||
|
||||
tools:
|
||||
php_code_coverage:
|
||||
enabled: true
|
||||
test_command: phpunit -c phpunit.xml.dist
|
||||
filter:
|
||||
paths: ["src/*"]
|
||||
php_code_sniffer:
|
||||
enabled: true
|
||||
config:
|
||||
standard: PSR2
|
||||
filter:
|
||||
paths: ["src/*"]
|
||||
php_cpd:
|
||||
enabled: true
|
||||
excluded_dirs: ["examples", "tests", "vendor"]
|
||||
php_cs_fixer:
|
||||
enabled: true
|
||||
config:
|
||||
level: all
|
||||
filter:
|
||||
paths: ["src/*", "tests/*"]
|
||||
php_loc:
|
||||
enabled: true
|
||||
php_mess_detector:
|
||||
enabled: true
|
||||
filter:
|
||||
paths: ["src/*"]
|
||||
php_pdepend:
|
||||
enabled: true
|
||||
excluded_dirs: ["tests", "examples", "vendor"]
|
||||
php_analyzer:
|
||||
filter:
|
||||
paths: ["src/*", "tests/*"]
|
||||
sensiolabs_security_checker: true
|
@ -0,0 +1,16 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- composer self-update
|
||||
- composer install
|
||||
- pyrus install pear/PHP_CodeSniffer
|
||||
- phpenv rehash
|
||||
|
||||
script:
|
||||
- phpcs --standard=psr2 src/
|
||||
- phpunit --coverage-text
|
@ -0,0 +1,20 @@
|
||||
(c) 2013 David Desberg <david@daviddesberg.com>
|
||||
Contributions (c) 2013 Pieter Hordijk <info@pieterhordijk.com>
|
||||
|
||||
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.
|
@ -0,0 +1,101 @@
|
||||
PHPoAuthLib
|
||||
===========
|
||||
PHPoAuthLib provides oAuth support in PHP 5.3+ and is very easy to integrate with any project which requires an oAuth client.
|
||||
|
||||
[](https://travis-ci.org/Lusitanian/PHPoAuthLib)
|
||||
[](https://scrutinizer-ci.com/g/Lusitanian/PHPoAuthLib/)
|
||||
[](https://scrutinizer-ci.com/g/Lusitanian/PHPoAuthLib/)
|
||||
[](https://packagist.org/packages/lusitanian/oauth)
|
||||
[](https://packagist.org/packages/lusitanian/oauth)
|
||||
|
||||
Installation
|
||||
------------
|
||||
This library can be found on [Packagist](https://packagist.org/packages/lusitanian/oauth).
|
||||
The recommended way to install this is through [composer](http://getcomposer.org).
|
||||
|
||||
Edit your `composer.json` and add:
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"lusitanian/oauth": "~0.3"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And install dependencies:
|
||||
|
||||
```bash
|
||||
$ curl -sS https://getcomposer.org/installer | php
|
||||
$ php composer.phar install
|
||||
```
|
||||
|
||||
Features
|
||||
--------
|
||||
- PSR-0 compliant for easy interoperability
|
||||
- Fully extensible in every facet.
|
||||
- You can implement any service with any custom requirements by extending the protocol version's `AbstractService` implementation.
|
||||
- You can use any HTTP client you desire, just create a class utilizing it which implements `OAuth\Common\Http\ClientInterface` (two implementations are included)
|
||||
- You can use any storage mechanism for tokens. By default, session, in-memory and Redis.io (requires PHPRedis) storage mechanisms are included. Implement additional mechanisms by implementing `OAuth\Common\Token\TokenStorageInterface`.
|
||||
|
||||
Service support
|
||||
---------------
|
||||
The library supports both oAuth 1.x and oAuth 2.0 compliant services. A list of currently implemented services can be found below.
|
||||
|
||||
Included service implementations
|
||||
--------------------------------
|
||||
- OAuth1
|
||||
- BitBucket
|
||||
- Etsy
|
||||
- FitBit
|
||||
- Flickr
|
||||
- Scoop.it!
|
||||
- Tumblr
|
||||
- Twitter
|
||||
- Xing
|
||||
- Yahoo
|
||||
- OAuth2
|
||||
- Amazon
|
||||
- BitLy
|
||||
- Box
|
||||
- Dailymotion
|
||||
- Dropbox
|
||||
- Facebook
|
||||
- Foursquare
|
||||
- GitHub
|
||||
- Google
|
||||
- Harvest
|
||||
- Heroku
|
||||
- Instagram
|
||||
- LinkedIn
|
||||
- Mailchimp
|
||||
- Microsoft
|
||||
- PayPal
|
||||
- Pocket
|
||||
- Reddit
|
||||
- RunKeeper
|
||||
- SoundCloud
|
||||
- Vkontakte
|
||||
- Yammer
|
||||
- more to come!
|
||||
|
||||
Examples
|
||||
--------
|
||||
Examples of basic usage are located in the examples/ directory.
|
||||
|
||||
Usage
|
||||
------
|
||||
For usage with complete auth flow, please see the examples. More in-depth documentation will come with release 1.0.
|
||||
|
||||
Framework Integration
|
||||
---------------------
|
||||
* Lithium: Sébastien Charrier has written [an adapter](https://github.com/scharrier/li3_socialauth) for the library.
|
||||
* Laravel 4: Dariusz Prząda has written [a service provider](https://github.com/artdarek/oauth-4-laravel) for the library.
|
||||
|
||||
Extensions
|
||||
----------
|
||||
* Extract normalized user data from OAuth Services with the library [PHPoAuthUserData](https://github.com/Oryzone/PHPoAuthUserData) by Luciano Mammino
|
||||
|
||||
Tests
|
||||
------
|
||||
To run the tests, you must install dependencies with `composer install --dev`
|
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "lusitanian/oauth",
|
||||
"description": "PHP 5.3+ oAuth 1/2 Library",
|
||||
"keywords": ["oauth", "authentication", "authorization", "security"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Desberg",
|
||||
"email": "david@daviddesberg.com"
|
||||
},
|
||||
{
|
||||
"name": "Pieter Hordijk",
|
||||
"email": "info@pieterhordijk.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/http-foundation": "~2.1",
|
||||
"predis/predis": "0.8.*@dev",
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/http-foundation": "Allows using the Symfony Session storage backend.",
|
||||
"predis/predis": "Allows using the Redis storage backend.",
|
||||
"ext-openssl": "Allows for usage of secure connections with the stream-based HTTP client."
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"OAuth": "src",
|
||||
"OAuth\\Unit": "tests"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Amazon service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Flávio Heleno <flaviohbatista@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Amazon;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['amazon']['key'],
|
||||
$servicesCredentials['amazon']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Amazon service using the credentials, http client, storage mechanism for the token and profile scope
|
||||
/** @var $amazonService Amazon */
|
||||
$amazonService = $serviceFactory->createService('amazon', $credentials, $storage, array('profile'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from Amazon, get the token
|
||||
$token = $amazonService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($amazonService->request('/user/profile'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique Amazon user id is: ' . $result['user_id'] . ' and your name is ' . $result['name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $amazonService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Amazon!</a>";
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token from the BitBucket service
|
||||
*
|
||||
* PHP version 5.4
|
||||
* @author Ændrew Rininsland <me@aendrew.com>
|
||||
*
|
||||
* Shamelessly cribbed from work by:
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth1\Service\BitBucket;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// We need to use a persistent storage to save the token, because oauth1 requires the token secret received before'
|
||||
// the redirect (request token request) in the access token request.
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['bitbucket']['key'],
|
||||
$servicesCredentials['bitbucket']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the BitBucket service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $bbService BitBucket */
|
||||
$bbService = $serviceFactory->createService('BitBucket', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['oauth_token'])) {
|
||||
$token = $storage->retrieveAccessToken('BitBucket');
|
||||
|
||||
// This was a callback request from BitBucket, get the token
|
||||
$bbService->requestAccessToken(
|
||||
$_GET['oauth_token'],
|
||||
$_GET['oauth_verifier'],
|
||||
$token->getRequestTokenSecret()
|
||||
);
|
||||
|
||||
// Send a request now that we have access token
|
||||
$result = json_decode($bbService->request('user/repositories'));
|
||||
|
||||
echo('The first repo in the list is ' . $result[0]->name);
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
// extra request needed for oauth1 to request a request token :-)
|
||||
$token = $bbService->requestRequestToken();
|
||||
|
||||
$url = $bbService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with BitBucket!</a>";
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Bitly service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Bitly;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['bitly']['key'],
|
||||
$servicesCredentials['bitly']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Bitly service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $bitlyService Bitly */
|
||||
$bitlyService = $serviceFactory->createService('bitly', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from bitly, get the token
|
||||
$bitlyService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($bitlyService->request('user/info'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique user id is: ' . $result['data']['login'] . ' and your name is ' . $result['data']['display_name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $bitlyService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Bitly!</a>";
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Bootstrap the library
|
||||
*/
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* Setup error reporting
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
/**
|
||||
* Setup the timezone
|
||||
*/
|
||||
ini_set('date.timezone', 'Europe/Amsterdam');
|
||||
|
||||
/**
|
||||
* Create a new instance of the URI class with the current URI, stripping the query string
|
||||
*/
|
||||
$uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
|
||||
$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
|
||||
$currentUri->setQuery('');
|
||||
|
||||
/**
|
||||
* Load the credential for the different services
|
||||
*/
|
||||
require_once __DIR__ . '/init.php';
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Box service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @author Antoine Corcy <contact@sbin.dk>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Box;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['box']['key'],
|
||||
$servicesCredentials['box']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Box service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $boxService Box */
|
||||
$boxService = $serviceFactory->createService('box', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// retrieve the CSRF state parameter
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : null;
|
||||
|
||||
// This was a callback request from box, get the token
|
||||
$token = $boxService->requestAccessToken($_GET['code'], $state);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($boxService->request('/users/me'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your Box name is ' . $result['name'] . ' and your email is ' . $result['login'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $boxService->getAuthorizationUri();
|
||||
// var_dump($url);
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Box!</a>";
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Dailymotion service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Mouhamed SEYE <mouhamed@seye.pro>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Dailymotion;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['dailymotion']['key'],
|
||||
$servicesCredentials['dailymotion']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Dailymotion service using the credentials, http client, storage mechanism for the token and email scope
|
||||
/** @var $dailymotionService Dailymotion */
|
||||
$dailymotionService = $serviceFactory->createService('dailymotion', $credentials, $storage, array('email'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from Dailymotion, get the token
|
||||
$token = $dailymotionService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($dailymotionService->request('/me?fields=email,id'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique Dailymotion user id is: ' . $result['id'] . ' and your email is ' . $result['email'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $dailymotionService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Dailymotion!</a>";
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Dropbox service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Flávio Heleno <flaviohbatista@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Dropbox;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['dropbox']['key'],
|
||||
$servicesCredentials['dropbox']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Dropbox service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $dropboxService Dropbox */
|
||||
$dropboxService = $serviceFactory->createService('dropbox', $credentials, $storage, array());
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from Dropbox, get the token
|
||||
$token = $dropboxService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($dropboxService->request('/account/info'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique Dropbox user id is: ' . $result['uid'] . ' and your name is ' . $result['display_name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $dropboxService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Dropbox!</a>";
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Etsy service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Iñaki Abete <inakiabt+github@gmail.com>
|
||||
* @copyright Copyright (c) 2013 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth1\Service\Etsy;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['etsy']['key'],
|
||||
$servicesCredentials['etsy']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Etsy service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $etsyService Etsy */
|
||||
$etsyService = $serviceFactory->createService('Etsy', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['oauth_token'])) {
|
||||
$token = $storage->retrieveAccessToken('Etsy');
|
||||
|
||||
// This was a callback request from Etsy, get the token
|
||||
$etsyService->requestAccessToken(
|
||||
$_GET['oauth_token'],
|
||||
$_GET['oauth_verifier'],
|
||||
$token->getRequestTokenSecret()
|
||||
);
|
||||
|
||||
// Send a request now that we have access token
|
||||
$result = json_decode($etsyService->request('/private/users/__SELF__'));
|
||||
|
||||
echo 'result: <pre>' . print_r($result, true) . '</pre>';
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$response = $etsyService->requestRequestToken();
|
||||
$extra = $response->getExtraParams();
|
||||
$url = $extra['login_url'];
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Etsy!</a>";
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Facebook service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Benjamin Bender <bb@codepoet.de>
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Facebook;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['facebook']['key'],
|
||||
$servicesCredentials['facebook']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Facebook service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $facebookService Facebook */
|
||||
$facebookService = $serviceFactory->createService('facebook', $credentials, $storage, array());
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from facebook, get the token
|
||||
$token = $facebookService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($facebookService->request('/me'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $facebookService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Facebook!</a>";
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the FitBit service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth1\Service\FitBit;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['fitbit']['key'],
|
||||
$servicesCredentials['fitbit']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the FitBit service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $fitbitService FitBit */
|
||||
$fitbitService = $serviceFactory->createService('FitBit', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['oauth_token'])) {
|
||||
$token = $storage->retrieveAccessToken('FitBit');
|
||||
|
||||
// This was a callback request from fitbit, get the token
|
||||
$fitbitService->requestAccessToken(
|
||||
$_GET['oauth_token'],
|
||||
$_GET['oauth_verifier'],
|
||||
$token->getRequestTokenSecret()
|
||||
);
|
||||
|
||||
// Send a request now that we have access token
|
||||
$result = json_decode($fitbitService->request('user/-/profile.json'));
|
||||
|
||||
echo 'result: <pre>' . print_r($result, true) . '</pre>';
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
// extra request needed for oauth1 to request a request token :-)
|
||||
$token = $fitbitService->requestRequestToken();
|
||||
|
||||
$url = $fitbitService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with FitBit!</a>";
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Flickr service
|
||||
*
|
||||
* @author Christian Mayer <thefox21at@gmail.com>
|
||||
* @copyright Copyright (c) 2013 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth1\Service\Flickr;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
use OAuth\Common\Http\Client\CurlClient;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__.'/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['flickr']['key'],
|
||||
$servicesCredentials['flickr']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Flickr service using the credentials, http client and storage mechanism for the token
|
||||
$flickrService = $serviceFactory->createService('Flickr', $credentials, $storage);
|
||||
|
||||
$step = isset($_GET['step']) ? (int)$_GET['step'] : null;
|
||||
|
||||
$oauth_token = isset($_GET['oauth_token']) ? $_GET['oauth_token'] : null;
|
||||
$oauth_verifier = isset($_GET['oauth_verifier']) ? $_GET['oauth_verifier'] : null;
|
||||
|
||||
if($oauth_token && $oauth_verifier){
|
||||
$step = 2;
|
||||
}
|
||||
|
||||
switch($step){
|
||||
default:
|
||||
print "<a href='".$currentUri->getRelativeUri().'?step=1'."'>Login with Flickr!</a>";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
if($token = $flickrService->requestRequestToken()){
|
||||
$oauth_token = $token->getAccessToken();
|
||||
$secret = $token->getAccessTokenSecret();
|
||||
|
||||
if($oauth_token && $secret){
|
||||
$url = $flickrService->getAuthorizationUri(array('oauth_token' => $oauth_token, 'perms' => 'write'));
|
||||
header('Location: '.$url);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$token = $storage->retrieveAccessToken('Flickr');
|
||||
$secret = $token->getAccessTokenSecret();
|
||||
|
||||
if($token = $flickrService->requestAccessToken($oauth_token, $oauth_verifier, $secret)){
|
||||
$oauth_token = $token->getAccessToken();
|
||||
$secret = $token->getAccessTokenSecret();
|
||||
|
||||
$storage->storeAccessToken('Flickr', $token);
|
||||
|
||||
header('Location: '.$currentUri->getAbsoluteUri().'?step=3');
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$xml = simplexml_load_string($flickrService->request('flickr.test.login'));
|
||||
print "status: ".(string)$xml->attributes()->stat."\n";
|
||||
break;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Foursquare service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Foursquare;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['foursquare']['key'],
|
||||
$servicesCredentials['foursquare']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Foursquare service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $foursquareService Foursquare */
|
||||
$foursquareService = $serviceFactory->createService('foursquare', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from foursquare, get the token
|
||||
$foursquareService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($foursquareService->request('users/self'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique foursquare user id is: ' . $result['response']['user']['id'] . ' and your name is ' . $result['response']['user']['firstName'] . $result['response']['user']['lastName'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $foursquareService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Foursquare!</a>";
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Github service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\GitHub;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['github']['key'],
|
||||
$servicesCredentials['github']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the GitHub service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $gitHub GitHub */
|
||||
$gitHub = $serviceFactory->createService('GitHub', $credentials, $storage, array('user'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from github, get the token
|
||||
$gitHub->requestAccessToken($_GET['code']);
|
||||
|
||||
$result = json_decode($gitHub->request('user/emails'), true);
|
||||
|
||||
echo 'The first email on your github account is ' . $result[0];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $gitHub->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Github!</a>";
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Google service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Google;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['google']['key'],
|
||||
$servicesCredentials['google']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Google service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $googleService Google */
|
||||
$googleService = $serviceFactory->createService('google', $credentials, $storage, array('userinfo_email', 'userinfo_profile'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from google, get the token
|
||||
$googleService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $googleService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Google!</a>";
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file sets up the information needed to test the examples in different environments.
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var array A list of all the credentials to be used by the different services in the examples
|
||||
*/
|
||||
$servicesCredentials = array(
|
||||
'amazon' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'bitbucket' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'bitly' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'box' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'dailymotion' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'dropbox' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'etsy' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'facebook' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'fitbit' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'flickr' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'foursquare' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'github' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'google' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'instagram' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'linkedin' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'mailchimp' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'microsoft' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'paypal' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'pocket' => array(
|
||||
'key' => '',
|
||||
),
|
||||
'reddit' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'runkeeper' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'scoopit' => array(
|
||||
'key' => '',
|
||||
'secret' => ''
|
||||
),
|
||||
'soundcloud' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'tumblr' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'twitter' => array(
|
||||
'key' => '',
|
||||
'secret' => '',
|
||||
),
|
||||
'yahoo' => array(
|
||||
'key' => '',
|
||||
'secret' => ''
|
||||
),
|
||||
'yammer' => array(
|
||||
'key' => '',
|
||||
'secret' => ''
|
||||
),
|
||||
);
|
||||
|
||||
/** @var $serviceFactory \OAuth\ServiceFactory An OAuth service factory. */
|
||||
$serviceFactory = new \OAuth\ServiceFactory();
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Instagram service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @author Hannes Van De Vreken <vandevreken.hannes@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Instagram;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['instagram']['key'],
|
||||
$servicesCredentials['instagram']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
$scopes = array('basic', 'comments', 'relationships', 'likes');
|
||||
|
||||
// Instantiate the Instagram service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $instagramService Instagram */
|
||||
$instagramService = $serviceFactory->createService('instagram', $credentials, $storage, $scopes);
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from Instagram, get the token
|
||||
$instagramService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($instagramService->request('users/self'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique instagram user id is: ' . $result['data']['id'] . ' and your name is ' . $result['data']['full_name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $instagramService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Instagram!</a>";
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Linkedin service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @author Antoine Corcy <contact@sbin.dk>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Linkedin;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['linkedin']['key'],
|
||||
$servicesCredentials['linkedin']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Linkedin service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $linkedinService Linkedin */
|
||||
$linkedinService = $serviceFactory->createService('linkedin', $credentials, $storage, array('r_basicprofile'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// retrieve the CSRF state parameter
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : null;
|
||||
|
||||
// This was a callback request from linkedin, get the token
|
||||
$token = $linkedinService->requestAccessToken($_GET['code'], $state);
|
||||
|
||||
// Send a request with it. Please note that XML is the default format.
|
||||
$result = json_decode($linkedinService->request('/people/~?format=json'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your linkedin first name is ' . $result['firstName'] . ' and your last name is ' . $result['lastName'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $linkedinService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Linkedin!</a>";
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Mailchimp service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Hannes Van De Vreken <vandevreken.hannes@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Mailchimp;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
$_SERVER['SERVER_PORT'] = 80;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['mailchimp']['key'],
|
||||
$servicesCredentials['mailchimp']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Mailchimp service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $mailchimpService Mailchimp */
|
||||
$mailchimpService = $serviceFactory->createService('mailchimp', $credentials, $storage, array());
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from mailchimp, get the token
|
||||
$token = $mailchimpService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = $mailchimpService->request('/users/profile.json');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo $result; exit;
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $mailchimpService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Mailchimp!</a>";
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Microsoft service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Microsoft;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['microsoft']['key'],
|
||||
$servicesCredentials['microsoft']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Microsoft service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $microsoft Microsoft */
|
||||
$microsoft = $serviceFactory->createService('microsoft', $credentials, $storage, array('basic'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from Microsoft, get the token
|
||||
$token = $microsoft->requestAccessToken($_GET['code']);
|
||||
|
||||
var_dump($token);
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $microsoft->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Microsoft!</a>";
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the PayPal service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Flávio Heleno <flaviohbatista@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Paypal;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['paypal']['key'],
|
||||
$servicesCredentials['paypal']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the PayPal service using the credentials, http client, storage mechanism for the token and profile/openid scopes
|
||||
/** @var $paypalService PayPal */
|
||||
$paypalService = $serviceFactory->createService('paypal', $credentials, $storage, array('profile', 'openid'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from PayPal, get the token
|
||||
$token = $paypalService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($paypalService->request('/identity/openidconnect/userinfo/?schema=openid'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique PayPal user id is: ' . $result['user_id'] . ' and your name is ' . $result['name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $paypalService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with PayPal!</a>";
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Pocket service.
|
||||
*
|
||||
* @author Christian Mayer <thefox21at@gmail.com>
|
||||
* @copyright Copyright (c) 2014 Christian Mayer <thefox21at@gmail.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Pocket;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
use OAuth\Common\Http\Client\CurlClient;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__.'/bootstrap.php';
|
||||
|
||||
$step = isset($_GET['step']) ? (int)$_GET['step'] : null;
|
||||
$code = isset($_GET['code']) ? $_GET['code'] : null;
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['pocket']['key'],
|
||||
null, // Pocket API doesn't have a secret key. :S
|
||||
$currentUri->getAbsoluteUri().($code ? '?step=3&code='.$code : '')
|
||||
);
|
||||
|
||||
// Instantiate the Pocket service using the credentials, http client and storage mechanism for the token
|
||||
$pocketService = $serviceFactory->createService('Pocket', $credentials, $storage);
|
||||
|
||||
switch($step){
|
||||
default:
|
||||
print '<a href="'.$currentUri->getRelativeUri().'?step=1">Login with Pocket</a>';
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$code = $pocketService->requestRequestToken();
|
||||
header('Location: '.$currentUri->getRelativeUri().'?step=2&code='.$code);
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$url = $pocketService->getAuthorizationUri(array('request_token' => $code));
|
||||
header('Location: '.$url);
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$token = $pocketService->requestAccessToken($code);
|
||||
$accessToken = $token->getAccessToken();
|
||||
$extraParams = $token->getExtraParams();
|
||||
|
||||
print 'User: '.$extraParams['username'].'<br />';
|
||||
print 'Access Token: '.$accessToken;
|
||||
break;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Reddit service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author Connor Hindley <conn.hindley@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\Reddit;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['reddit']['key'],
|
||||
$servicesCredentials['reddit']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Reddit service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $reddit Reddit */
|
||||
$reddit = $serviceFactory->createService('Reddit', $credentials, $storage, array('identity'));
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// retrieve the CSRF state parameter
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : null;
|
||||
|
||||
// This was a callback request from reddit, get the token
|
||||
$reddit->requestAccessToken($_GET['code'], $state);
|
||||
|
||||
$result = json_decode($reddit->request('api/v1/me.json'), true);
|
||||
|
||||
echo 'Your unique reddit user id is: ' . $result['id'] . ' and your username is ' . $result['name'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $reddit->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with Reddit!</a>";
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token from the RunKeeper service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\RunKeeper;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['runkeeper']['key'],
|
||||
$servicesCredentials['runkeeper']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the Runkeeper service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $runkeeperService RunKeeper */
|
||||
$runkeeperService = $serviceFactory->createService('RunKeeper', $credentials, $storage, array());
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from RunKeeper, get the token
|
||||
$token = $runkeeperService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($runkeeperService->request('/user'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique RunKeeper user id is: ' . $result['userID'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $runkeeperService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with RunKeeper!</a>";
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of making API calls for the ScoopIt service
|
||||
*
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2013 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth1\Service\ScoopIt;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__.'/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['scoopit']['key'],
|
||||
$servicesCredentials['scoopit']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the ScoopIt service using the credentials, http client and storage mechanism for the token
|
||||
$scoopItService = $serviceFactory->createService('ScoopIt', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['oauth_token'])) {
|
||||
$token = $storage->retrieveAccessToken('ScoopIt');
|
||||
|
||||
// This was a callback request from ScoopIt, get the token
|
||||
$scoopItService->requestAccessToken(
|
||||
$_GET['oauth_token'],
|
||||
$_GET['oauth_verifier'],
|
||||
$token->getRequestTokenSecret()
|
||||
);
|
||||
|
||||
// Send a request now that we have access token
|
||||
$result = json_decode($scoopItService->request('profile'));
|
||||
|
||||
echo 'result: <pre>' . print_r($result, true) . '</pre>';
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
// extra request needed for oauth1 to request a request token :-)
|
||||
$token = $scoopItService->requestRequestToken();
|
||||
|
||||
$url = $scoopItService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with ScoopIt!</a>";
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the SoundCloud service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use OAuth\OAuth2\Service\SoundCloud;
|
||||
use OAuth\Common\Storage\Session;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
|
||||
/**
|
||||
* Bootstrap the example
|
||||
*/
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Session storage
|
||||
$storage = new Session();
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$servicesCredentials['soundcloud']['key'],
|
||||
$servicesCredentials['soundcloud']['secret'],
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
// Instantiate the SoundCloud service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $soundcloudService SoundCloud */
|
||||
$soundcloudService = $serviceFactory->createService('soundCloud', $credentials, $storage);
|
||||
|
||||
if (!empty($_GET['code'])) {
|
||||
// This was a callback request from SoundCloud, get the token
|
||||
$soundcloudService->requestAccessToken($_GET['code']);
|
||||
|
||||
// Send a request with it
|
||||
$result = json_decode($soundcloudService->request('me.json'), true);
|
||||
|
||||
// Show some of the resultant data
|
||||
echo 'Your unique user id is: ' . $result['id'] . ' and your name is ' . $result['username'];
|
||||
|
||||
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
|
||||
$url = $soundcloudService->getAuthorizationUri();
|
||||
header('Location: ' . $url);
|
||||
} else {
|
||||
$url = $currentUri->getRelativeUri() . '?go=go';
|
||||
echo "<a href='$url'>Login with SoundCloud!</a>";
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example of retrieving an authentication token of the Tumblr service
|
||||
*
|
||||
* PHP version 5.4
|
||||
*
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Pieter Hordijk <info@pieterhordijk.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||