renanivo / authoritarian
An OAuth 2 client for PHP with multiple authorization flows support
Installs: 99
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/renanivo/authoritarian
Requires
- guzzle/guzzle: ~3.5
Requires (Dev)
- apigen/apigen: *
- behat/behat: 2.4.*@stable
- behat/mink-extension: *
- behat/mink-selenium2-driver: *
- henrikbjorn/phpspec-code-coverage: dev-master
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2025-09-23 06:40:26 UTC
README
An OAuth 2 client for PHP with multiple authorization flows support
Install
Get composer and execute:
php composer.phar require renanivo/authoritarian
Usage
Just setup your flow and request an access token:
Client Credentials Flow
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\ClientCredentialsFlow; $flow = new ClientCredentialsFlow(); $flow->setClientCredential('client id', 'client secret'); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
Authorization-Code Flow
in the login page:
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\AuthorizationCodeFlow; $flow = new AuthorizationCodeFlow(); $flow->setAuthorizationUrl('http://example.com/oauth/authorize'); $flow->setClientCredential('client id', 'client secret'); $flow->setRedirectUri('http://example.com/callback'); header('Location: ' . $flow->getAuthUrl());
in the callback page:
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\AuthorizationCodeFlow; $flow = new AuthorizationCodeFlow(); $flow->setClientCredential('client id', 'client secret'); $flow->setCode($_GET['code']); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
Resource Owner Password
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\ResourceOwnerPasswordFlow; $flow = new ResourceOwnerPasswordFlow( 'username', 'password' ); $flow->setClientCredential('client id', 'client secret'); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
Generate Docs
-
Download apigen.phar:
curl -sS http://apigen.org/installer | php
-
Run ApiGen:
php apigen.phar generate