ghlogin

package
v0.0.0-...-7c66ffc Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const GitHubSessionProfile = gitHubSessionType("GitHubSession")

GitHubSessionProfile is the value for the profile in the context

View Source
const (

	// GithubAuthCookieName is the name of the cookie used to store the session ID
	GithubAuthCookieName = "ee_github_session"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	Config Config // Config is the authenticator's configuration
	// contains filtered or unexported fields
}

Authenticator is the GH OAuth interface. Create this to enable authentication

func New

func New(config Config) (*Authenticator, error)

New creates a new GH authenticator instance

func (*Authenticator) AuthHandlerFunc

func (a *Authenticator) AuthHandlerFunc(funcToWrap http.HandlerFunc) http.HandlerFunc

AuthHandlerFunc returns a http.HandlerFunc wrapped in an authentication handler. If the user isn't authenticated it will return a 401 response, otherwise the wrapped function will be executed.

func (*Authenticator) Handler

func (a *Authenticator) Handler() http.Handler

Handler returns a handler for the (local) GitHub resource

func (*Authenticator) Profile

func (a *Authenticator) Profile(r *http.Request) (Profile, error)

Profile reads the user profile from the http.Request context

func (*Authenticator) ServeHTTP

func (a *Authenticator) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Authenticator) StartSessionChecker

func (a *Authenticator) StartSessionChecker()

StartSessionChecker launches a profile checker goroutine

type Config

type Config struct {
	ClientID           string `param:"desc=OAuth client ID"`
	CallbackURL        string `param:"desc=Callback URL for client;default=http://localhost:8080/github/callback"`
	ClientSecret       string `param:"desc=OAuth Client secret"`
	LoginSuccess       string `param:"desc=Redirect after successful login;default=/"`
	LogoutSuccess      string `param:"desc=Redirect after logout;default=/"`
	SecureCookie       bool   `param:"desc=Secure flag on cookie;default=false"`
	DBDriver           string `param:"desc=Database driver (postgres, sqlite3);default=sqlite3"`
	DBConnectionString string `param:"desc=Connection string for session store;default=:memory:"`
}

Config is the GitHub OAuth application settings. Create new one at https://github.com/settings/developers. You must enroll into the GH Developer Program to create an application. Read more at https://developer.github.com/

type Profile

type Profile struct {
	AvatarURL string `json:"avatarUrl"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	Login     string `json:"loginName"`
}

Profile contains the GitHub profile

func (*Profile) Scan

func (p *Profile) Scan(src interface{}) error

Scan implements the sql.Scanner interface (to read from db fields). This makes it possible to write to and from the "tags" field in sql drivers

func (*Profile) Value

func (p *Profile) Value() (driver.Value, error)

Value implements the driver.Valuer interface (for writing to db fields)

type Session

type Session struct {
	Expires     int64
	SessionID   string
	AccessToken string
	Profile     Profile
}

Session is the stored session data

type SessionStore

type SessionStore interface {
	// PutState inserts a new state nonce in the storage. The nonce will never expire
	PutState(state string) error

	// RemoveState removes a state nonce from the storage. An error is returned if the
	// nonce does not exist.
	RemoveState(state string) error

	// CreateSession creates a new session in the store. The lastUpdate parameter is the expire
	// time (in ns) for the session
	CreateSession(sessionID string, accessToken string, expires int64, profile Profile) error

	// GetSession returns the session from. The ignoreOlder is the current time stamp
	GetSession(sessionID string, ingnoreOlder int64) (Session, error)

	// RemoveSession removes the session from the store
	RemoveSession(sessionID string) error

	// GetSessions returns sessions with the last_update parameter set to the current value
	GetSessions(time int64) ([]Session, error)

	// RefreshSession refreshes a session expire time
	RefreshSession(sessionID string, checkInterval int64) error
}

SessionStore is the interface for the session back-end store.

func NewSQLSessionStore

func NewSQLSessionStore(driver, connectionString string) (SessionStore, error)

NewSQLSessionStore creates a sql-backed session streo

Jump to

Keyboard shortcuts

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