An open API service indexing awesome lists of open source software.

https://github.com/devtronic/oauth-client

A simple OAuth client
https://github.com/devtronic/oauth-client

Last synced: 5 months ago
JSON representation

A simple OAuth client

Awesome Lists containing this project

README

          

# OAuth Client
This is a simple client for OAuth Services (W.I.P.)

Currently included services:
- Battle.net
- Dropbox
- Facebook
- GitHub
- Google
- Instagram
- PayPal
- Shopify
- Slack
- Twitter

More OAuth2 services coming soon

## Installation
```bash
$ composer require devtronic/oauth-client
```

## Usage

OAuth 2.0
```php
',
$clientSecret = '',
$redirectUrl = '' # This script for example
);

# Prints all available scopes
# print_r($ro->getScopes());

$scopes = [
'https://www.googleapis.com/auth/userinfo.profile'
];

if (!isset($_REQUEST['code'])) {
header('location: ' . $ro->getAuthorizeUrl($scopes));
exit;
} else {
$token = $ro->getAccessToken($scopes, $_REQUEST['code']);

$client = new \GuzzleHttp\Client(['verify' => false]);
$res = $client->request('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json', [
'headers' => [
'Authorization' => sprintf('Bearer ' . $token->getToken()),
]
]);
echo '

';

print_r(json_decode($res->getBody()->getContents(), true));
}
```

OAuth 1.0
```php
',
$consumerSecret = '',
$redirectUrl = '' # This script for example
);

if (!isset($_REQUEST['oauth_token'])) {
header('location: ' . $ro->getAuthorizeUrl());
exit;
} else {
// Get the Token
$token = $ro->getAccessToken($_REQUEST['oauth_token'], $_REQUEST['oauth_verifier']);

// Start your own request
$client = new \GuzzleHttp\Client(['verify' => false]);
$url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
$res = $client->request('GET', $url, [
'headers' => [
// Sign the request and get the auth header
'Authorization' => $ro->getAuthorizationHeader(
'GET', # Request Method
$url, # Requested URL
[], # Request Parameters (GET, POST etc.)
$token # The previously received AccessToken
),
]
]);
echo '

';

print_r(json_decode($res->getBody()->getContents(), true));
}
```