Implementation of standard OAuth V2 for Password Grant type in Golang and its native HTTP server.
POST oauth2/clients HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/json
Request:
curl -k --location --request POST 'https://127.0.0.1:8080/oauth2/clients' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "johndoe1",
"password": "johnspassword1"
}'
Response:
{
"client_id": "a9a6b145-fafe-415c-a92e-c79cbd57567d"
}
POST oauth2/token HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/x-www-form-urlencoded
Request:
curl -k --location --request POST 'https://127.0.0.1:8080/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=johndoe1' \
--data-urlencode 'password=johnspassword1'
Response:
{
"access_token": "MmVjZGFiNmY4Y2E2OTQ1ZWNmMGQyNmZlODZhYWM5YzFhNDliYzZiNzNkNmY2MjBmYThiMzM3NTEyODE1ZTc1YjNiZTcxODI3YjFjZDkzZDYyODRkODljZjdjMDU3NWY4M2Y2NjdiODg4ZTliZDIwMzlmMTRlYjkxZGEyYmFkMDM=",
"token_type": "Bearer",
"expires_in": 3600
}
make deploy
In order to run debugger you could create a config on your IDE and enable DEBUG
env variable in your
local environment. You will need database & cache storage from docker; you could enable them with:
make debug
- SSL For Postgres
- SSL & Password for Redis
- Cert for Creation of Token (Could be from Infra or Inside the code)
- TLS Server Listener
- Use Docker Secret to share passwords
Author: Hadi Tajallaei
Copyright © 2023 Syniol Limited. All rights reserved.
Please see a LICENSE file