Documentation
¶
Index ¶
- Constants
- type Authenticator
- func (a *Authenticator) AuthHandlerFunc(funcToWrap http.HandlerFunc) http.HandlerFunc
- func (a *Authenticator) Handler() http.Handler
- func (a *Authenticator) Profile(r *http.Request) (Profile, error)
- func (a *Authenticator) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *Authenticator) StartSessionChecker()
- type Config
- type Profile
- type Session
- type SessionStore
Constants ¶
const GitHubSessionProfile = gitHubSessionType("GitHubSession")
GitHubSessionProfile is the value for the profile in the context
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
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