Go Middleware to limit access to Web content (not APIs) using Google Sign-in For Websites (Google Authentication).
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
configuration
handlers/login
logger
session
templates
tokenverifier
vendor
Makefile
README.md
handler.go

README.md

gauthmiddleware

Go Middleware to limit access to Web content (not APIs) using Google Sign-in For Websites (Google Authentication).

It renders a basic login screen for non-authenticated users, then issues a session cookie for logged-in users.

Installation

go get github.com/a-h/gauthmiddleware
// Load settings from environment variables or use gauthmiddleware.NewWithConfiguration to customise.
handler, err := gauthmiddleware.New()

Usage

Set the required environment variables:

  • SESSION_ENCRYPTION_KEY
    • A Base64 encoded key used to encrypt and decrypt cookies. Should be 32 bytes of data.
    • cat /dev/random | head -c 32 | base64
  • COOKIE_NAME
    • The name used for the session cookie generated by the site once Google Authentication is complete, e.g. auth-session.
  • SET_SECURE_FLAG
    • The site should only be access via HTTPS. When set to true, session cookies are set with the secure flag. The only reason to set this to false is during testing.
  • GOOGLE_AUTH_CLIENT_ID
  • GOOGLE_ALLOWED_DOMAINS
    • A comma-separated list of GSuite domains which are allowed access to the content, or an asterisk to allow all.