authn

package
v0.0.0-...-599a714 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 1 Imported by: 0

README

Authentication

This starter app has Authentication baked into it, so that you can trivially support user accounts and profiles. These logins are stateful and reversible, and this initial demo demonstrates how to safely plumb authentication data throughout an App.

Note: This app is built to require authentication on every page except for the Log-In page (which logged out users will have to be able to see). You can modify this by changing the WithAuthorization method.

Authentication is split into session management (setting and retrieving cookies, user creation, etc), and Firebase specific logic implementations of generic authentication functions.

The three primary methods in this package are all in session/session.go:

  • LoginHandler is an HTTP handler for handling a login attempt. It handles cases of existing and new users, and finds or creates information about the user in the database.
  • LogoutHandler is the analogous HTTP handler for handling a logout attempt - it clears the user's cookies, and makes it so that the user cannot refresh their session going forward.
  • WithAuthorization is an HTTP handler which redirects the user to login if they aren't yet authorized, and populates authorization data (most critically, the UserID of the authorized user) on the context for all business logic (and in our case, graphql resolvers) to use.

Documentation

Overview

Package authn provides some domain types shared across our auth system.

Index

Constants

View Source
const (
	UnknownProvider = Provider("")
	Google          = Provider("GOOGLE")
	EmailAndPass    = Provider("EMAIL_AND_PASS")
	Facebook        = Provider("FACEBOOK")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider string

Provider is the underlying auth provider, since our auth system will delegate to multiple under the hood.

type Token

type Token struct {
	UserInfo *UserInfo
	AuthTime time.Time
}

Token is a representation of a user's auth token, which contains basic user information and when they authenticated with the system.

type UserID

type UserID string

UserID is a unique ID assigned to an authenticated user by our auth system.

type UserInfo

type UserInfo struct {
	UserID       UserID   `json:"user_id"` // The Auth-provider's UserId
	Email        string   `json:"email"`
	AuthProvider Provider `json:"auth_provider"`
}

UserInfo contains basic information relevant for authentication.

Directories

Path Synopsis
Package fireauth is a wrapper around Firebase auth that works with our session cookie management.
Package fireauth is a wrapper around Firebase auth that works with our session cookie management.
Package session provides functionality for providing auth based on session cookies.
Package session provides functionality for providing auth based on session cookies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL