Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexmasterov/oauth2-stackexchange
StackExchange.com Provider for the OAuth 2.0 Client
https://github.com/alexmasterov/oauth2-stackexchange
league-oauth2 oauth2 oauth2-provider oauth2-stackexchange
Last synced: about 2 hours ago
JSON representation
StackExchange.com Provider for the OAuth 2.0 Client
- Host: GitHub
- URL: https://github.com/alexmasterov/oauth2-stackexchange
- Owner: AlexMasterov
- License: mit
- Created: 2017-01-13T21:17:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T03:33:13.000Z (over 6 years ago)
- Last Synced: 2024-04-24T02:46:18.408Z (7 months ago)
- Topics: league-oauth2, oauth2, oauth2-provider, oauth2-stackexchange
- Language: PHP
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StackExchange.com Provider for the OAuth 2.0 Client
[![Latest Stable Version](https://poser.pugx.org/alexmasterov/oauth2-stackexchange/v/stable)](https://packagist.org/packages/alexmasterov/oauth2-stackexchange)
[![License](https://img.shields.io/packagist/l/alexmasterov/oauth2-stackexchange.svg)](https://github.com/AlexMasterov/oauth2-stackexchange/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/AlexMasterov/oauth2-stackexchange.svg)](https://travis-ci.org/AlexMasterov/oauth2-stackexchange)
[![Code Coverage](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-stackexchange/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-stackexchange/?branch=master)
[![Code Quality](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-stackexchange/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-stackexchange/?branch=master)This package provides [StackExchange.com](https://stackexchange.com) OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).
## Installation
The suggested installation method is via [composer](https://getcomposer.org/):
```sh
composer require alexmasterov/oauth2-stackexchange
```## Usage
### Configuration
```php
$provider = new AlexMasterov\OAuth2\Client\Provider\StackExchange([
'clientId' => '{client_id}',
'clientSecret' => '{client_secret}',
'redirectUri' => '{redirect_uri}',
'state' => '{state}',
'key' => '{key}',
'site' => '{site}',
]);
```### Authorization
```php
if (!empty($_GET['error'])) {
// Got an error, probably user denied access
exit('Got error: ' . $_GET['error']);
}if (empty($_GET['code'])) {
// If we don't have an authorization code then get one
$provider->authorize();
}// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);// Optional: Now you have a token you can look up a users profile data
try {
// We got an access token, let's now get the owner details
$ownerDetails = $provider->getResourceOwner($token);
} catch (\Exception $e) {
// Failed to get user details
exit('Something went wrong: ' . $e->getMessage());
}// Use this to interact with an API on the users behalf
echo $token->accessToken;
```