pkg

package
v0.0.0-...-0617947 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoginCookieName = "X-Gateway-User"
	LoginHeaderName = "X-Gateway-User"
)

Variables

This section is empty.

Functions

func NewLoginCallbackHandler

func NewLoginCallbackHandler(
	cookieGenerator CookieGenerator,
	stateGenerator StateGenerator,
	googleOAuth GoogleOAuth,
) libhttp.WithError

Types

type Code

type Code string

Code used for authorization

func (Code) String

func (c Code) String() string
type Cookie struct {
	jwt.StandardClaims
	// contains filtered or unexported fields
}

Cookie storing the user pass-through information that is passed on authentication.

func (Cookie) HTTPCookie

func (s Cookie) HTTPCookie() *http.Cookie

HTTPCookie based on Cookie

func (Cookie) String

func (s Cookie) String() string

type CookieGenerator

type CookieGenerator interface {
	Generate(ctx context.Context, user string) (Cookie, error)
	Decode(ctx context.Context, cookie string) (Cookie, error)
}

CookieGenerator generates and decodes secure cookies

func NewCookieGenerator

func NewCookieGenerator(key []byte) CookieGenerator

NewCookieGenerator using key to sign cookie tokens

type GoogleOAuth

type GoogleOAuth interface {
	AuthCodeURL(state State) string
	UserInfo(ctx context.Context, code Code) (*UserInfo, error)
}

GoogleOAuth defines the interface used for running a Google OAuth flow

func NewGoogleOAuth

func NewGoogleOAuth(
	clientID string,
	clientSecret string,
	redirectURL string,
	hostedDomain string,
) GoogleOAuth

NewGoogleOAuth returns an implementation of the Google OAuth flow using the provided credentials

type LoginMiddleware

type LoginMiddleware interface {
	Middleware(handler http.Handler) http.Handler
}

func NewLoginMiddleware

func NewLoginMiddleware(
	cookieGenerator CookieGenerator,
	stateGenerator StateGenerator,
	googleOAuth GoogleOAuth,
	callbackPath string,
) LoginMiddleware

NewLoginMiddleware for validating request against a jwt secret

type State

type State struct {
	Origin string `json:"origin"`
	jwt.StandardClaims
	// contains filtered or unexported fields
}

State stores a requests state for passing through the oauth2 flow, ensuring CSRF protection and a fluent experience by passing the origin url.

func (State) String

func (s State) String() string

type StateGenerator

type StateGenerator interface {
	Generate(ctx context.Context, originURL string) (State, error)
	Decode(ctx context.Context, token string) (State, error)
}

StateGenerator generates and decodes secure states

func NewStateGenerator

func NewStateGenerator(key []byte) StateGenerator

NewStateGenerator using key to sign state tokens

type UserInfo

type UserInfo struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	VerifiedEmail bool   `json:"verified_email"`
	Picture       string `json:"picture"`
	HD            string `json:"hd"`
}

UserInfo returned by the OAuth provider

Jump to

Keyboard shortcuts

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