https://github.com/syniol/golang-oauth2
OAuth 2.1 Password Grant Type implementation in Go
https://github.com/syniol/golang-oauth2
authentication docker docker-compose go golang oauth2 password-grant postgres postgresql redis redis-cache
Last synced: 6 months ago
JSON representation
OAuth 2.1 Password Grant Type implementation in Go
- Host: GitHub
- URL: https://github.com/syniol/golang-oauth2
- Owner: syniol
- License: other
- Created: 2023-03-24T22:47:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-06T22:26:25.000Z (11 months ago)
- Last Synced: 2025-08-06T23:22:01.173Z (11 months ago)
- Topics: authentication, docker, docker-compose, go, golang, oauth2, password-grant, postgres, postgresql, redis, redis-cache
- Language: Go
- Homepage:
- Size: 73.2 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.1 Password Grant Type in Golang

Implementation of standard OAuth 2.1 for Password Grant type in Golang and its native HTTP server.
## Healthcheck API
```text
GET oauth2/healthz HTTP/1.1
Host: 127.0.0.1
Content-Type: text/plain
```
__Request:__
```bash
curl -k --location --request GET 'https://127.0.0.1/healthz'
```
__Response:__
Status code `200` (OK) and a simple body response `ok` indicates API is working and operational.
```text
ok
```
## Clients API
Clients endpoint is responsible for creating a new client/user to be inserted in database.
```text
POST oauth2/clients HTTP/1.1
Host: 127.0.0.1
Content-Type: application/json
```
__Request:__
```bash
curl -k --location --request POST 'https://127.0.0.1/oauth2/clients' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "johndoe",
"password": "johnspassword1"
}'
```
__Response:__
```json
{
"client_id": "a9a6b145-fafe-415c-a92e-c79cbd57567d"
}
```
## Token API
After client registration you can create a token sending a `POST` request to this endpoint.
```text
POST oauth2/token HTTP/1.1
Host: 127.0.0.1
Content-Type: application/x-www-form-urlencoded
```
__Request:__
```bash
curl -k --location --request POST 'https://127.0.0.1/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=johndoe' \
--data-urlencode 'password=johnspassword1'
```
__Response:__
```json
{
"access_token": "MmVjZGFiNmY4Y2E2OTQ1ZWNmMGYz...FkMDM=",
"token_type": "Bearer",
"expires_in": 3600
}
```
## Up & Running
There are a few commands available, you could explore the available options by running `make`. This
should give you a glossary of available methods. For example to deploy the service, you can run:
```bash
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:
```bash
make debug
```

### Todos
* [ ] Add more documents about this repository and RFC Standard for OAuth 2.1 especially for `password_grant`
* [ ] Convert Http Error response to JSON response `errors: []`
* [ ] Investigate possibility of volume share for Redis & Go (app) to share TLS certs
* [ ] Separate the Docker network for proxy and app to exclude Database (Postgres) & Cache (Redis)
* [ ] Increase code coverage
#### Credits
Author: [Hadi Tajallaei](mailto:hadi@syniol.com)
Copyright © 2023-2025 Syniol Limited. All rights reserved.
_Please see a [LICENSE file](https://github.com/syniol/golang-oauth-password-grant/blob/main/LICENSE)_