Skip to content

beercanx/oauth-api-go

Repository files navigation

A Go based OAuth API

An exercise into how to create an HTTP service using GO, following guidance from:

Then gave up doing vanilla Go HTTP server; because I'm a wimp and used a framework instead:

Went back a day later and continued to re-read the "after 13 years" blog post to create the Hello, World! http sample.

Regardless, I have decided to continue with gin itself, but following the coding styles suggested; such as not storing dependencies in a struct but passing them through the functions.

Requirements

Structure

This project attempts to follow the standard Go project layout as defined here: https://github.com/golang-standards/project-layout/blob/master/README.md

├── cmd                         # Main applications for this project.
│   └── server
│       └── main.go
├── internal                    # Private application and library code. 
│   ├── app
│   │   ├── token-exchange
│   │   ├── token-introspection
│   │   ├── token-revocation
│   │   └── ...etc
│   └── pkg
│       ├── client
│       ├── grant
│       ├── scope
│       └── ...etc
├── scripts
│   └── http                    # Jetbrains HTTP Client requests
└── README.md

Testing

The standard Go approach to unit testing

go test -v ./...

To include the benchmark tests

go test -v ./... -bench .

To only run the benchmark tests

go test -v ./... -bench . -run ^$

Building

Rebuilding the autogenerated mocks

Using mockery, we can auto-generate the standard mocks for interfaces.

go generate

Which is just a different way to doing

mockery

The OAuth server

An OAuth server, using mostly the Gin web framework that wraps around the Go http library.

go build ./cmd/server
./server

Check out the password grant

So yeah, the password grant is deprecated; but it's a quick lazy way to start.

curl -vvv -X POST -H 'Content-Type: application/x-www-form-urlencoded' -u 'aardvark:badger' -d 'grant_type=password&scope=basic&username=aardvark&password=P%4055w0rd' http://127.0.0.1:8080/token

About

A GO project that re-implements my OAuth API project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages