auth

package
v0.0.97 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig added in v0.0.88

type AuthConfig struct {
	RequestVars        *gohttp.RequestVarMap
	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 added in v0.0.88

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

func (*AuthConfig) EnsureLoginMiddleware added in v0.0.97

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

*

  • Redirects users to login screen of they are not logged in
  • @param req Request object
  • @param res Response object
  • @param next next function

func (*AuthConfig) EnsureReasonableDefaults added in v0.0.89

func (a *AuthConfig) EnsureReasonableDefaults()

*

  • Ensures that config values have reasonable defaults.

func (*AuthConfig) ExtractUserInfo added in v0.0.89

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

*

  • 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 added in v0.0.89

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

type AuthDB added in v0.0.8

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

func NewAuthDB added in v0.0.8

func NewAuthDB(gormdb *gorm.DB) *AuthDB

func (*AuthDB) DeleteAuthFlowById added in v0.0.8

func (adb *AuthDB) DeleteAuthFlowById(entityId string) bool

func (*AuthDB) EnsureChannel added in v0.0.8

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

func (*AuthDB) EnsureIdentity added in v0.0.8

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

func (*AuthDB) GetAuthFlowById added in v0.0.8

func (adb *AuthDB) GetAuthFlowById(entityId string) (*AuthFlow, error)

func (*AuthDB) GetChannel added in v0.0.8

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

func (*AuthDB) GetIdentity added in v0.0.8

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

func (*AuthDB) SaveAuthFlow added in v0.0.8

func (adb *AuthDB) SaveAuthFlow(entity *AuthFlow) (err error)

*

  • Creates a new auth session object to track a login request.

func (*AuthDB) SaveChannel added in v0.0.8

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

func (*AuthDB) SaveIdentity added in v0.0.8

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

type AuthFlow

type AuthFlow struct {
	dal.BaseEntity

	// A unique Auth Session ID
	ID string

	// Kind of login being done
	Provider string

	// When this Auth session expires;
	ExpiresIn time.Time // 300

	// Handler that will continue the flow after a successful AuthFlow.
	HandlerName string // "login"

	// Parameters for the handler to continue with.
	HandlerParams dal.JsonField `gorm:"type:text"`
}

func (*AuthFlow) HasKey

func (af *AuthFlow) HasKey() bool

And others things here

type CallbackRequest

type CallbackRequest struct {
	Hostname string

	Path string

	// Method to call the callback URL on
	Method string

	// Headers for this request
	Headers utils.StringMap
	// 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 added in v0.0.8

func NewChannel(provider string, loginId string, params utils.StringMap) *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 added in v0.0.8

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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