Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zemkogabor/oauth2-server
Simple OAuth 2.0 Server based on Thephpleague and Slim framework.
https://github.com/zemkogabor/oauth2-server
oauth2 oauth2-server slim-framework thephpleague-oauth2
Last synced: about 6 hours ago
JSON representation
Simple OAuth 2.0 Server based on Thephpleague and Slim framework.
- Host: GitHub
- URL: https://github.com/zemkogabor/oauth2-server
- Owner: zemkogabor
- License: mit
- Created: 2023-02-16T19:31:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-14T21:19:10.000Z (about 1 year ago)
- Last Synced: 2023-11-14T22:27:26.424Z (about 1 year ago)
- Topics: oauth2, oauth2-server, slim-framework, thephpleague-oauth2
- Language: PHP
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OAuth 2.0 Server
Simple OAuth 2.0 Server based on Thephpleague and Slim framework.
Supported Grants:- [Password Grant](https://oauth2.thephpleague.com/authorization-server/resource-owner-password-credentials-grant/)
- [Refresh Token Grant](https://oauth2.thephpleague.com/authorization-server/refresh-token-grant/)## Install Dev (Docker)
1. Set environments with te following examples files
```bash
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;'`
2. Install backend framework and dependencies
```bash
docker-compose run --rm php composer install
```3. Start containers
```bash
docker-compose up -d
```4. Generate keys
```bash
mkdir -p var/keysopenssl genrsa -out var/keys/private.key
openssl rsa -in var/keys/private.key -pubout -out var/keys/public.keychmod 600 var/keys/private.key
chmod 600 var/keys/public.key
```5. Run migrations
```bash
docker-compose exec php php cli.php migrations:migrate
```6. Create client
confidential:
```bash
docker-compose exec php php cli.php client:create "Test Client" "http://127.0.0.1" "secret" --confidential
```public:
```bash
docker-compose exec php php cli.php client:create "Test Client" "http://127.0.0.1"
```7. Create user
```bash
docker-compose exec php php cli.php user:create "[email protected]" "Test User Name" "secret"
```8. 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"
}'
```9. Get active user
```
curl --location --request GET 'http://127.0.0.1.nip.io:8888/user' \
--header 'Authorization: Bearer '
```## PHP CS Fixer
```bash
docker-compose exec php bash
php ./vendor/bin/php-cs-fixer fix --diff --dry-run --config .php-cs-fixer.php --verbose
```## Build prod image
```bash
docker buildx build -t /oauth-server: . --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
```yaml
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/
```