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
- Host: GitHub
- URL: https://github.com/devtronic/oauth-client
- Owner: devtronic
- License: mit
- Created: 2017-09-03T16:22:26.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-12T05:11:16.000Z (almost 8 years ago)
- Last Synced: 2024-12-30T21:29:12.634Z (over 1 year ago)
- Language: PHP
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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));
}
```