A minimal OAuth 2.0 Authorization Code flow test using the custom CentralAuth
provider (extends league/oauth2-client
).
This example uses the CentralAuth provider for the PHP OAuth client library.
For complete CentralAuth configuration and API documentation, visit: https://docs.centralauth.com
- Authorization Code + PKCE
- Custom CentralAuth provider with POST userinfo retrieval
- Session-based login + dashboard
- Install dependencies:
- PHP 7.4+ (or compatible)
- Composer
- Install libraries:
composer install
- Create your environment file:
copy .env.example .env # Windows
# OR
cp .env.example .env # macOS/Linux
- Edit
.env
with your real credentials and endpoints. - Place this folder under your web root (e.g. XAMPP
htdocs
). - Visit:
http://localhost/index.php
Variable | Description |
---|---|
OAUTH_CLIENT_ID | CentralAuth client ID |
OAUTH_CLIENT_SECRET | CentralAuth client secret |
OAUTH_REDIRECT_URI | Redirect URI of your application |
OAUTH_AUTHORIZATION_URL | Authorization/ Login endpoint (e.g. https://centralauth.com/login) |
OAUTH_TOKEN_URL | Token / verification endpoint (e.g. https://centralauth.com/api/v1/verify) |
OAUTH_RESOURCE_OWNER_DETAILS_URL | User info endpoint (e.g. https://centralauth.com/api/v1/userinfo) |
use CentralAuth\OAuth2\Client\Provider\CentralAuth; // From centralauth/oauth2-centralauth package
$provider = new CentralAuth([
'clientId' => $_ENV['OAUTH_CLIENT_ID'],
'clientSecret' => $_ENV['OAUTH_CLIENT_SECRET'],
'redirectUri' => $_ENV['OAUTH_REDIRECT_URI'],
'authorization_url' => $_ENV['OAUTH_AUTHORIZATION_URL'],
'token_url' => $_ENV['OAUTH_TOKEN_URL'],
'resource_owner_details_url' => $_ENV['OAUTH_RESOURCE_OWNER_DETAILS_URL']
]);
- Do not commit
.env
(ensure.gitignore
contains it) - Use production secrets through real environment configuration (Apache, Nginx, container, etc.)
MIT