auth

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoggedInUser added in v0.0.5

func GetLoggedInUser(ctx context.Context) string

func SetLoggedInUser added in v0.0.5

func SetLoggedInUser(ctx context.Context, userID string) context.Context

Types

type AuthConfig

type AuthConfig struct {
	SessionGetter      func(r *http.Request, param string) any
	CallbackURLParam   string
	DefaultRedirectURL string
	GetRedirURL        func(r *http.Request) string
	UserParamName      string
	NoLoginRedirect    bool
}

func (*AuthConfig) EnsureLogin

func (a *AuthConfig) EnsureLogin(w http.ResponseWriter, r *http.Request) bool

func (*AuthConfig) EnsureLoginMiddleware

func (a *AuthConfig) EnsureLoginMiddleware(next http.Handler) http.Handler

*

  • Redirects users to login screen if they are not logged in

func (*AuthConfig) EnsureReasonableDefaults

func (a *AuthConfig) EnsureReasonableDefaults()

*

  • Ensures that config values have reasonable defaults.

func (*AuthConfig) ExtractUserInfo

func (a *AuthConfig) ExtractUserInfo(next http.Handler) http.Handler

*

  • Extracts user info from the request and saves it into current user.
  • Can be used by further middleware down the line to get the request's
  • user info

func (*AuthConfig) GetLoggedInUserId

func (a *AuthConfig) GetLoggedInUserId(r *http.Request) string

type AuthDB

type AuthDB struct {
	// contains filtered or unexported fields
}

func NewAuthDB

func NewAuthDB(gormdb *gorm.DB) *AuthDB

func (*AuthDB) EnsureChannel

func (adb *AuthDB) EnsureChannel(provider string, loginId string, params utils.StrMap) (*Channel, bool)

func (*AuthDB) EnsureIdentity

func (adb *AuthDB) EnsureIdentity(idType string, idKey string, params utils.StrMap) (*Identity, bool)

func (*AuthDB) GetChannel

func (adb *AuthDB) GetChannel(provider string, loginId string) (*Channel, error)

func (*AuthDB) GetIdentity

func (adb *AuthDB) GetIdentity(idType string, idKey string) (*Identity, error)

func (*AuthDB) SaveChannel

func (adb *AuthDB) SaveChannel(entity *Channel) (err error)

func (*AuthDB) SaveIdentity

func (adb *AuthDB) SaveIdentity(entity *Identity) (err error)

type CallbackRequest

type CallbackRequest struct {
	Hostname string

	Path string

	// Method to call the callback URL on
	Method string

	// Headers for this request
	Headers utils.StrMap
	// contains filtered or unexported fields
}

func (*CallbackRequest) FullURL

func (c *CallbackRequest) FullURL() string

type Channel

type Channel struct {
	dal.BaseEntity

	Provider string `gorm:"primaryKey"`
	LoginId  string `gorm:"primaryKey"`

	/**
	 * Credentials for this channel (like access tokens, hashed passwords etc).
	 */
	Credentials dal.JsonField `gorm:"type:text"`

	/**
	 * Profile as passed by the provider of the channel.
	 */
	Profile dal.JsonField `gorm:"type:text"`

	/**
	 * When does this channel expire and needs another login/auth.
	 */
	ExpiresAt time.Time

	// The identity that this channel is verifying.
	IdentityKey string
}

*

  • Channel's represented federated verification objects. For example a Google
  • Signin would ensure that the user that goes through this flow will end up
  • with a Google signin Channel - which would verify a particular identity type.

func NewChannel

func NewChannel(provider string, loginId string, params utils.StrMap) *Channel

func (*Channel) HasIdentity

func (ch *Channel) HasIdentity() bool

func (*Channel) HasKey

func (ch *Channel) HasKey() bool

func (*Channel) Key

func (ch *Channel) Key() string

type Identity

type Identity struct {
	dal.BaseEntity

	// Type of identity being verified (eg email, phone etc).
	IdentityType string `gorm:"primaryKey"`

	// The key specific to the identity (eg an email address or a phone number etc).
	//
	// type + key should be unique through out the system.
	IdentityKey string `gorm:"primaryKey"`

	// The primary user that this identity can be associated with.
	// Identities do not need to be explicitly associted with a user especially
	// in systems where a single Identity can be used to front several users
	PrimaryUser string
}

*

  • An identify is a unique global "address" corresponding to a user.
  • For example the identify abc@example.com is a unique identify regardless
  • of which Channel is verifying it. Multiple channels can verify the same
  • entity, eg open auth by github, FB or Google can verify the same email
  • address.

func NewIdentity

func NewIdentity(idType string, idKey string) *Identity

func (*Identity) HasKey

func (id *Identity) HasKey() bool

func (*Identity) HasUser

func (id *Identity) HasUser() bool

func (*Identity) Key

func (id *Identity) Key() string

Jump to

Keyboard shortcuts

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