Simple OAuth 2.0 Server based on Thephpleague and Slim framework.
Supported Grants:
- Set environments with te following examples files
cp _env/php.example.env _env/php.env
cp _env/postgres.example.env _env/postgres.env
Encryption key generate: php -r 'echo base64_encode(random_bytes(32)), PHP_EOL;'
- Install backend framework and dependencies
docker-compose run --rm php composer install
- Start containers
docker-compose up -d
- Generate keys
mkdir -p var/keys
openssl genrsa -out var/keys/private.key
openssl rsa -in var/keys/private.key -pubout -out var/keys/public.key
chmod 600 var/keys/private.key
chmod 600 var/keys/public.key
- Run migrations
docker-compose exec php php cli.php migrations:migrate
- Create client
confidential:
docker-compose exec php php cli.php client:create "Test Client" "http://127.0.0.1" "secret" --confidential
public:
docker-compose exec php php cli.php client:create "Test Client" "http://127.0.0.1"
- Create user
docker-compose exec php php cli.php user:create "[email protected]" "Test User Name" "secret"
- Login
curl --location --request POST 'http://127.0.0.1:8888/access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
"grant_type": "password",
"client_id": "713446ac-4950-4166-aa77-6b78f3265c0a",
"client_secret": "secret",
"scope": "email basic name",
"username": "[email protected]",
"password": "secret"
}'
- Get active user
curl --location --request GET 'http://127.0.0.1.nip.io:8888/user' \
--header 'Authorization: Bearer <secret>'
docker-compose exec php bash
php ./vendor/bin/php-cs-fixer fix --diff --dry-run --config .php-cs-fixer.php --verbose
docker buildx build -t <your_registry>/oauth-server:<version> . --platform=linux/arm64,linux/amd64 -f _docker/php/prod/Dockerfile --push
- The prod image already contains a pre-made var/keys folder, but not the keys. They must be created using the method mentioned above.
- Docker-compose example for prod image
version: "3.9"
services:
php_prod:
image: oauth2-server-prod-image
env_file:
- _env/php.env
restart: unless-stopped
volumes:
- ./var/keys:/app/var/keys
ports:
- "8888:8888"
command: php -S 0.0.0.0:8888 -t /app/public/