Summary: OAuth 2 in Action code samples, re-written in golang.
I am learning golang. As an exercise, I will be re-writing the code samples from OAuth 2 in Action, by Justin Richer and Antonio Sanso, in Go.
The original sources are written in JavaScript. They use Express.js, Underscore.js and Consolidate.js.
You are welcome to submit PRs and issues, but keep in mind I am doing this as an exercise in learning Go, so I may not merge any PRs or resolve any issues until I have completed the project. Also bear in mind the "Assumptions" below.
The point of the book is to learn about the inner workings of OAuth2, and not to learn any particular programming language. For this reason, these translated golang versions of the book's exercises will keep things as simple as possible, meaning:
- Using native features in golang and the standard library wherever possible (e.g.,
net/http, not Gin;html/template, not Templ) - Not necessarily doing things the "correct" way, either from a professional software development perspective (I'm an architect and systems engineer, not a professional software engineer), or from an idiomatic golang perspective.
- There are more idiomatic ways to structure the code, like having
cmdanduidirectories, but I'm keeping the structure here close to that of the originaljssources. - Updated the Appendix files to explicity create a ServeMux.
- Happy New Year!
- My
Taskfile.ymlsyntax was wrong. The file has been fixed, and optimized to handle the eventual long list of exercises. - The code and templates for the authorization server and resource server Appendix code are updated. They're a mess, but they work. I'll spend some time cleaning these up before moving on, as these will serve as the templates for the rest of the exercises.
What has changed? Other than golang itself!
- The directory structure for each exercise has changed, compared with the original javascript, as follows: within each exercise directory, each of the actors (the client, the authorization server, and the resource server) have their own sub-directories, and each actor's HTML template file is stored in a
files/directory therein. - In place of Express.js, we will use the standard library's
net/httppackage. - In place of Underscore.js and Consolidate.js, we will use the the standard library's
html/templatepackage and other built-in functionality. - The template files for the sample code from Appendix A have been converted to use
html/templatesyntax. - The code for the OAuth client in Go is complete. Running the client
main.goresults in the same user experience as the original JavaScript.
I've also added a Taskfile.yml so you can launch each exercise with a single task (modern-day make for old people like me) command. E.g.,
$ task ap-A-ex-0
The task names match the directory names for each exercise. Run task [taskname] from the project root directory. brew install go-task if you are on a Mac and using Homebrew. Using task is optional. You can always go run the individual main.go files for each exercise.