Skip to content

syniol/golang-oauth-password-grant

Repository files navigation

OAuth 2 Password Grant Type in Golang

Implementation of standard OAuth V2 for Password Grant type in Golang and its native HTTP server.

Clients API

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"
}

Token API

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
}

Up & Running

  make deploy

Debug

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

img

Todos

  • 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

Credits

Author: Hadi Tajallaei

Copyright © 2023 Syniol Limited. All rights reserved.

Please see a LICENSE file

About

OAuth 2.1 Password Grant Type implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published