authentication

package
v0.0.0-...-98cd694 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Unlicense Imports: 37 Imported by: 0

Documentation

Overview

Package authentication implements a user passwords layer for a web server, issuing cookies, validating requests via middleware

Index

Constants

View Source
const (
	// DefaultCookieName is the default Cookie.BucketName.
	DefaultCookieName = "service_name_api_cookie"
	// DefaultCookieLifetime is how long a cookie is valid for.
	DefaultCookieLifetime = 24 * time.Hour
)
View Source
const (
	AuthProviderParamKey = "auth_provider"
)

Variables

View Source
var (
	// ErrNoSessionContextDataAvailable indicates no SessionContextData was attached to the request.
	ErrNoSessionContextDataAvailable = errors.New("no SessionContextData attached to session context data")
)
View Source
var Providers = wire.NewSet(
	ProvideService,
	wire.FieldsOf(new(*Config),
		"Cookies",
	),
)

Providers are our collection of what we provide to other services.

Functions

func FetchContextFromRequest

func FetchContextFromRequest(req *http.Request) (*types.SessionContextData, error)

FetchContextFromRequest fetches a SessionContextData from a request.

func ProvideOAuth2ServerImplementation

func ProvideOAuth2ServerImplementation(
	_ context.Context,
	logger logging.Logger,
	tracer tracing.Tracer,
	cfg *OAuth2Config,
	dataManager database.DataManager,
) *server.Server

func ProvideService

func ProvideService(
	ctx context.Context,
	logger logging.Logger,
	cfg *Config,
	authenticator authentication.Authenticator,
	dataManager database.DataManager,
	accountMembershipManager types.AccountUserMembershipDataManager,
	sessionManager *scs.SessionManager,
	encoder encoding.ServerEncoderDecoder,
	tracerProvider tracing.TracerProvider,
	publisherProvider messagequeue.PublisherProvider,
	secretGenerator random.Generator,
	featureFlagManager featureflags.FeatureFlagManager,
	analyticsReporter analytics.EventReporter,
	routeParamManager routing.RouteParamManager,
) (types.AuthService, error)

ProvideService builds a new AuthService.

Types

type Config

type Config struct {
	SSO                   SSOConfigs   `json:"sso,omitempty"                   toml:"sso,omitempty"`
	DataChangesTopicName  string       `json:"dataChanges,omitempty"           toml:"data_changes,omitempty"`
	Cookies               CookieConfig `json:"cookies,omitempty"               toml:"cookies,omitempty"`
	OAuth2                OAuth2Config `json:"oauth2,omitempty"                toml:"oauth2,omitempty"`
	Debug                 bool         `json:"debug,omitempty"                 toml:"debug,omitempty"`
	EnableUserSignup      bool         `json:"enableUserSignup,omitempty"      toml:"enable_user_signup,omitempty"`
	MinimumUsernameLength uint8        `json:"minimumUsernameLength,omitempty" toml:"minimum_username_length,omitempty"`
	MinimumPasswordLength uint8        `json:"minimumPasswordLength,omitempty" toml:"minimum_password_length,omitempty"`
	// contains filtered or unexported fields
}

Config represents our passwords configuration.

func (*Config) ValidateWithContext

func (cfg *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates a Config struct.

type CookieConfig

type CookieConfig struct {
	Name       string        `json:"name,omitempty"       toml:"name,omitempty"`
	Domain     string        `json:"domain,omitempty"     toml:"domain,omitempty"`
	HashKey    string        `json:"hashKey,omitempty"    toml:"hash_key,omitempty"`
	BlockKey   string        `json:"blockKey,omitempty"   toml:"signing_key,omitempty"`
	Lifetime   time.Duration `json:"lifetime,omitempty"   toml:"lifetime,omitempty"`
	SecureOnly bool          `json:"secureOnly,omitempty" toml:"secure_only,omitempty"`
	// contains filtered or unexported fields
}

CookieConfig holds our cookie settings.

func (*CookieConfig) ValidateWithContext

func (cfg *CookieConfig) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates a CookieConfig struct.

type GoogleSSOConfig

type GoogleSSOConfig struct {
	ClientID     string `json:"clientID,omitempty"     toml:"client_id,omitempty"`
	ClientSecret string `json:"clientSecret,omitempty" toml:"client_secret,omitempty"`
	CallbackURL  string `json:"callbackURL,omitempty"  toml:"callback_url,omitempty"`
	// contains filtered or unexported fields
}

type OAuth2Config

type OAuth2Config struct {
	Domain               string        `json:"domain"               toml:"domain,omitempty"`
	AccessTokenLifespan  time.Duration `json:"accessTokenLifespan"  toml:"access_token_lifespan,omitempty"`
	RefreshTokenLifespan time.Duration `json:"refreshTokenLifespan" toml:"refresh_token_lifespan,omitempty"`
	Debug                bool          `json:"debug"                toml:"debug,omitempty"`
	// contains filtered or unexported fields
}

OAuth2Config represents our database configuration.

func (OAuth2Config) ValidateWithContext

func (cfg OAuth2Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates a OAuth2Config struct.

type SSOConfigs

type SSOConfigs struct {
	Google GoogleSSOConfig `json:"google,omitempty" toml:"google,omitempty"`
}

Jump to

Keyboard shortcuts

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