auth

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package auth exposes interfaces for various auth methods.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionMissing     = fmt.Errorf("session is missing")
	ErrSessionInfoMissing = fmt.Errorf("session info is missing")
)

Functions

This section is empty.

Types

type EmailVerificationEmailFunc

type EmailVerificationEmailFunc func(ctx context.Context, verifyLink string) error

EmailVerificationEmailFunc is an email composer function.

type InviteUserEmailFunc

type InviteUserEmailFunc func(ctx context.Context, inviteLink string) error

InviteUserEmailFunc sends email with the given inviteLink.

type Provider

type Provider interface {
	// StoreSession stores the session in the values.
	StoreSession(context.Context, *sessions.Session, *SessionInfo) error

	// CheckRevoked checks if the auth has been revoked. It returns an error if
	// the auth does not exist or if the auth has been revoked.
	CheckRevoked(context.Context, *sessions.Session) error

	// ClearSession removes any information about this auth from the session.
	ClearSession(context.Context, *sessions.Session)

	// RevokeSession revokes the session in the upstream identity provider, if one
	// exists. This is a no-op for first-party identity. RevokeSession calls
	// ClearSession on success.
	RevokeSession(context.Context, *sessions.Session) error

	// CreateUser creates a user in the auth provider. If pass is "", the provider
	// creates and uses a random password.
	CreateUser(ctx context.Context, name, email, pass string, sendInvite bool, composer InviteUserEmailFunc) (bool, error)

	// SendResetPasswordEmail resets the given user's password. If the user does not exist,
	// the underlying provider determines whether it's an error or perhaps upserts
	// the account.
	SendResetPasswordEmail(ctx context.Context, email string, composer ResetPasswordEmailFunc) error

	// ChangePassword changes the users password. The additional authentication
	// information is provider-specific.
	ChangePassword(ctx context.Context, newPassword string, data interface{}) error

	// VerifyPasswordResetCode verifies the code is valid. It returns the email of
	// the user for which the code belongs.
	VerifyPasswordResetCode(ctx context.Context, code string) (string, error)

	// SendEmailVerificationEmail sends the email verification email for the
	// currently authenticated user. Data is arbitrary additional data that the
	// provider might need (like user ID) to send the verification.
	SendEmailVerificationEmail(ctx context.Context, email string, data interface{}, composer EmailVerificationEmailFunc) error

	// EmailAddress extracts the email address for this auth provider from the
	// session. It returns an error if the session does not exist.
	EmailAddress(context.Context, *sessions.Session) (string, error)

	// EmailVerified returns true if the current user is verified, false
	// otherwise.
	EmailVerified(context.Context, *sessions.Session) (bool, error)

	// MFAEnabled returns true if MFA is enabled, false otherwise.
	MFAEnabled(context.Context, *sessions.Session) (bool, error)
}

Provider is a generic authentication provider interface.

func NewFirebase

func NewFirebase(ctx context.Context, config *firebase.Config) (Provider, error)

NewFirebase creates a new auth provider for firebase.

func NewLocal

func NewLocal(ctx context.Context) (Provider, error)

NewLocal creates a new auth provider for local auth.

type ResetPasswordEmailFunc

type ResetPasswordEmailFunc func(ctx context.Context, resetLink string) error

ResetPasswordEmailFunc is an email composer function.

type SessionInfo

type SessionInfo struct {
	// Data is provider-specific information. The schema is determined by the
	// provider.
	Data map[string]interface{}

	// TTL is the session duration.
	TTL time.Duration
}

SessionInfo is a generic struct used to store session information. Not all providers use all fields.

Jump to

Keyboard shortcuts

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