auth

package
v0.0.0-...-557396d Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppUserKey is the session key for the app user
	AppUserKey key = "AppUser"
)

Variables

This section is empty.

Functions

func AutoMigrateModels

func AutoMigrateModels(db *gorm.DB) error

AutoMigrateModels ensures all models are present in the database

Types

type Model

type Model struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"created"`
	UpdatedAt time.Time  `json:"updated"`
	DeletedAt *time.Time `json:"-"`
}

Model is the basic data layout to be inherited

type Provider

type Provider struct {
	DB      *gorm.DB
	Session ProviderSession
}

Provider is a struct for auth

func CreateProvider

func CreateProvider(db *gorm.DB, sessionStore *sessions.CookieStore, sessionName, sessionSecret, sessionUserKey string) Provider

CreateProvider will initialize and return a new Provider

func (Provider) AddAppUserContext

func (a Provider) AddAppUserContext(next http.Handler) http.Handler

AddAppUserContext adds user information context

func (Provider) CreateUser

func (a Provider) CreateUser(user User) (User, error)

CreateUser creates a new user in the database

func (Provider) GetAllUsers

func (a Provider) GetAllUsers() ([]User, error)

GetAllUsers returns all users

func (Provider) GetUserBySSOID

func (a Provider) GetUserBySSOID(ssoID string) (User, error)

GetUserBySSOID returns a user by SSOID if it exists

func (Provider) GetUserFromContext

func (a Provider) GetUserFromContext(ctx context.Context) User

GetUserFromContext loads a user from context where it can

func (Provider) IsAuthenticated

func (a Provider) IsAuthenticated(req *http.Request) bool

IsAuthenticated returns true if the user has a signed session cookie.

func (Provider) IssueSession

func (a Provider) IssueSession() http.Handler

IssueSession issues a cookie session after successful Google login

func (Provider) LogoutHandler

func (a Provider) LogoutHandler(w http.ResponseWriter, req *http.Request)

LogoutHandler destroys the session on POSTs and redirects to home.

func (Provider) WithUserFromSession

func (a Provider) WithUserFromSession(s interface{}) (User, error)

WithUserFromSession loads a user from a session where it can

type ProviderSession

type ProviderSession struct {
	Store   *sessions.CookieStore
	Name    string
	Secret  string
	UserKey string
}

ProviderSession is a struct for a session

type User

type User struct {
	Model
	SSOID           string `gorm:"unique;not null;unique_index"`
	Email           string `gorm:"unique;not null;unique_index"`
	ProfileImageURL string
	Exists          bool
	APIToken        string `json:"-"`
}

User is a user object

Jump to

Keyboard shortcuts

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