Skip to content

Simple OAuth 2.0 Server based on Thephpleague and Slim framework.

License

Notifications You must be signed in to change notification settings

zemkogabor/oauth2-server

Repository files navigation

OAuth 2.0 Server

Simple OAuth 2.0 Server based on Thephpleague and Slim framework.

Supported Grants:

Install Dev (Docker)

  1. 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;'

  1. Install backend framework and dependencies
docker-compose run --rm php composer install
  1. Start containers
docker-compose up -d
  1. 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
  1. Run migrations
docker-compose exec php php cli.php migrations:migrate
  1. 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"
  1. Create user
docker-compose exec php php cli.php user:create "[email protected]" "Test User Name" "secret"
  1. 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"
}'
  1. Get active user
curl --location --request GET 'http://127.0.0.1.nip.io:8888/user' \
--header 'Authorization: Bearer <secret>'

PHP CS Fixer

docker-compose exec php bash
php ./vendor/bin/php-cs-fixer fix --diff --dry-run --config .php-cs-fixer.php --verbose

Build prod image

docker buildx build -t <your_registry>/oauth-server:<version> . --platform=linux/arm64,linux/amd64 -f _docker/php/prod/Dockerfile --push

Notes

  • 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/

About

Simple OAuth 2.0 Server based on Thephpleague and Slim framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published