handler

package
v0.0.0-...-3a2841b Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(store AuthDB, strategies strategy.Strategies, httpClient *http.Client) http.Handler

Auth takes the chosen provider and initiates authentication by redirecting the user to the 3rd party. It takes a number of parameters:

  • me: URL originally entered of who we are trying to authenticate
  • provider: 3rd party authentication provider that was chosen
  • profile: URL expected to be matched by the provider
  • redirect_uri: final URI to redirect to when auth is finished

func Callback

func Callback(store CallbackDB, strat strategy.Strategy, generator func() (string, error)) http.Handler

Callback handles the return from the authentication provider by delegating to the relevant strategy. If authentication was successful, and for the correct user, then it will redirect to the "redirect_uri" that the authentication flow was originally started with. A "code" parameter is returned which can be verified as belonging to the authenticated user for a short period of time.

func Choose

func Choose(baseURL string, store ChooseDB, strategies strategy.Strategies, chooseTemplate, meTemplate tmpl) http.Handler

Choose finds, for the "me" parameter, all authentication providers that can be used for authentication.

func Continue

func Continue(store ContinueDB, generator func() (string, error)) http.Handler

Continue handles a user choosing to authenticate using a previous session.

func Example

func Example(baseURL string, conf config.Config, store sessions.Store, tokenStore ExampleDB, welcomeTemplate, accountTemplate tmpl) http.HandlerFunc

Example implements a basic site using the authentication flow provided by this package.

func ExampleCallback

func ExampleCallback(baseURL string, store sessions.Store) http.HandlerFunc

ExampleCallback implements the authentication callback for Example. It verifies the code, then sets the value of "me" in a session cookie.

func ExampleForget

func ExampleForget(baseURL string, store sessions.Store, tokenStore ExampleDB) http.HandlerFunc

func ExampleGenerate

func ExampleGenerate(
	baseURL string,
	store sessions.Store,
	generator func(int) (string, error),
	tokenStore ExampleDB,
	templates tmpl,
) http.HandlerFunc

func ExamplePrivacy

func ExamplePrivacy(templates tmpl) http.HandlerFunc

func ExampleRevoke

func ExampleRevoke(baseURL string, store sessions.Store, tokenStore ExampleDB) http.HandlerFunc

ExampleRevoke removes the token for the client_id.

func ExampleSignIn

func ExampleSignIn(baseURL string, store sessions.Store) http.HandlerFunc

func ExampleSignOut

func ExampleSignOut(baseURL string, store sessions.Store) http.HandlerFunc

ExampleSignOut removes the value of "me" from the session cookie.

func PGP

func PGP(templates tmpl) http.HandlerFunc

PGP creates a http.Handler that serves a random challenge for the user to clearsign.

func Token

func Token(store TokenDB, generator func(int) (string, error)) http.Handler

func Verify

func Verify(store VerifyDB) http.Handler

Verify allows clients to check who a particular "code" belongs to, or whether it is invalid.

func WebSocket

func WebSocket(strategies strategy.Strategies, store WebSocketDB, relMe *microformats.RelMe) http.Handler

WebSocket returns a http.Handler that handles websocket connections. The client can request a set of authentication methods for a user.

Types

type AuthDB

type AuthDB interface {
	Session(string) (data.Session, error)
	SetProvider(me, provider, profileURI string) error
}

type CallbackDB

type CallbackDB interface {
	SaveLogin(http.ResponseWriter, *http.Request, string) error
	Session(string) (data.Session, error)
	CreateCode(me, code string, createdAt time.Time) error
}

type ChooseDB

type ChooseDB interface {
	Login(*http.Request) (string, error)
	CreateSession(data.Session) error
	Client(clientID, redirectURI string) (data.Client, error)
}

type ContinueDB

type ContinueDB interface {
	Login(*http.Request) (string, error)
	Session(string) (data.Session, error)
	CreateCode(me, code string, createdAt time.Time) error
}

type ExampleDB

type ExampleDB interface {
	CreateToken(data.Token) error
	Tokens(string) ([]data.Token, error)
	RevokeToken(string) error
	Forget(string) error
}

type TokenDB

type TokenDB interface {
	Code(string) (data.Code, error)
	Token(string) (data.Token, error)
	CreateToken(data.Token) error
	RevokeToken(string) error
}

type VerifyDB

type VerifyDB interface {
	Code(string) (data.Code, error)
}

type WebSocketDB

type WebSocketDB interface {
	Profile(string) (data.Profile, error)
	CacheProfile(data.Profile) error
}

Jump to

Keyboard shortcuts

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