PHP OAuth Server
30 Jul 2018Background
Grant Types 1
- Authorization Code
- Implicit
- Password
- Client Credentials
- Device Code
- Refresh Token
Definitions 2
- Resource Owner: The User
- Resource Server: The API
- Authorization Server: Often the same as the API server
- Client: The Third-Party Application
In php
https://www.sitepoint.com/creating-a-php-oauth-server/ https://github.com/phpmasterdotcom/CreatingAPHPOAuthServer https://github.com/zorrodg/mworell-oauth-php
include.php
OAuth2 Demo PHP [^oauth.net]
Need PHP 7.0 or above.
Download code
git clone https://github.com/bshaffer/oauth2-demo-php.git
Prepare config
cp data/parameters.json.dist data/parameters.json
{
"client_id": "demoapp",
"client_secret": "demopass",
"token_route": "grant", # first
"authorize_route": "authorize",
"resource_route": "access", #second
"resource_params": {},
"user_credentials": ["demouser", "testpass"],
"http_options": { "exceptions": false }
}
sed -i '' 's?"grant"?"http://localhost:8081/lockdin/token"?g' data/parameters.json
{
"client_id": "demoapp",
"client_secret": "demopass",
"token_route": "http://localhost:8081/lockdin/token",
"authorize_route": "authorize",
"resource_route": "access",
"resource_params": {},
"user_credentials": ["demouser", "testpass"],
"http_options": { "exceptions": false }
}
sed -i '' 's?"access"?"http://localhost:8081/lockdin/resource"?g' data/parameters.json
{
"client_id": "demoapp",
"client_secret": "demopass",
"token_route": "http://localhost:8081/lockdin/token",
"authorize_route": "authorize",
"resource_route": "http://localhost:8081/lockdin/resource",
"resource_params": {},
"user_credentials": ["demouser", "testpass"],
"http_options": { "exceptions": false }
}
Start server
cd web
# 8080 client and app
# 8081 oauth server
php -S localhost:8080 & php -S localhost:8081