A Go JWT wrapper which bundles common operations for JWT tokens. Makes pervasive use of the jwt Go implementation of JSON Web Tokens (JWT).
This provides functionality to create custom map claims, new JWTs, validity checks, refresh JWTs and check JWT content. It was built and intended for use with auth but can be used as a standalone.
This was part of a learning exercise to create auth which is a very rough Go equivalent of dotnet core Identity services.
See the tests for usage examples.
See [examples] for a http/appengine implementations which uses session and auth. This is written for appengine standard 2nd gen, but also works as a standalone.
This utilises the following fine pieces of work:
- jwt Go implementation of JSON Web Tokens (JWT)
- Segment's ksuid - K-Sortable Globally Unique IDs
- GCP's [Datastore Go client] and Storage Go client
Also uses:
- lidstromberg packages log, keypair and config. Please note that log and config do not require environment variables to be set, but keypair requires encryption keys to be set. Refer to the keypair package for further details. The easiest way to ensure all of these things are configured, is to refer to the auth package itself.
Install using go get.
$ go get -u github.com/lidstromberg/session
You will also need to export (linux/macOS) or create (Windows) some environment variables.
################################
# SESSION
################################
export JWT_DEBUGON="false"
export JWT_ISSUER="{{DOMAINNAME}}"
export JWT_EXTMIN="15"
export JWT_APPROLEDELIM=":"
################################
# GCP CREDENTIALS
################################
export GOOGLE_APPLICATION_CREDENTIALS="/PATH/TO/GCPCREDENTIALS.JSON"
(See Google Application Credentials)
If you want to run the authcore tests or the example implementations, then you will also require RSA certs for the jwt tokens. See keypair for details on how these are used.
If you intend to use GCP datastore as your backend, then you will require:
- A GCP project
- A GCP storage bucket (private) to store the jwt private/public keys (in the root of the bucket). See keypair for further details.
- Your GOOGLE_APPLICATION_CREDENTIALS json credentials key should be created with the following IAM scopes: 'Storage Object Viewer' and 'Storage Object Creator', or 'Storage Object Admin'.
File | Purpose |
---|---|
sessmgr.go | Logic manager |
sessmgr_test.go | Tests |
File | Purpose |
---|---|
config.go | Boot package parameters, environment var collection |
entity.go | Package structs |
errors.go | Package error definitions |
env | Package environment variables for local/dev installation |
gogets | Statements for go-getting required packages |