authenticator

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package authenticator provides a way to authenticate users using different methods.

Index

Constants

View Source
const (
	// CookieName is the name of the cookie used for session authentication.
	CookieName = "BP_OP_AUTH"
	// LoginKey is a key that is used to identify the login id.
	LoginKey = "loginid"
	// PasswordKey is a key that is used to identify the password.
	PasswordKey = "p"
	// UsernameKey is a key that is used to identify the username.
	UsernameKey = "u"
	// AuthenticatedKey is a key that is used to identify if the user has been authenticated in the middleware.
	AuthenticatedKey = "authenticated"
)

Variables

View Source
var ErrBadBindCreds = errors.New("incorrect username or password for BindUser")

ErrBadBindCreds for invalid authentication credentials

View Source
var ErrBadCreds = errors.New("incorrect username or password")

ErrBadCreds for invalid authentication credentials

View Source
var ErrInvalidSession = errors.New("failed to retrieve session")

ErrInvalidSession for when username or password are expected and not present

View Source
var ErrMissingCreds = errors.New("missing field 'credential'")

ErrMissingCreds is an error for when a google authentication payload doesn't have credentials

Functions

func AbortWithError

func AbortWithError(c *gin.Context, err error) error

AbortWithError aborts the gin context with the given error.

func HandleSessionError

func HandleSessionError(c *gin.Context, session sessions.Session, err error)

HandleSessionError handles the gin context and session after a non nil error is returned while getting session. It will clear the session and abort with error. Must call return during the gin handler function directly after.

func LoginIDFromSession

func LoginIDFromSession(session *sessions.Session) (login string, inSession bool)

LoginIDFromSession returns the login id from the session.

func LoginIDPasswordFromSession

func LoginIDPasswordFromSession(session *sessions.Session) (login, password string, inSession bool)

LoginIDPasswordFromSession returns the login id and password from the session.

Types

type Authenticator

type Authenticator interface {

	// Login takes in a ctx that has the username and password attached to it in some way. currently in either the Postform or the request Header.
	// This function should store some form of the user on the session to be used in the verify function.
	// The string returned is the unique identifier of the user that was just logged in
	// 			Ex: "email" in google, "DN (distinguished name)" in LDAP, or just the authenticator.LoginSession for system auth.
	// Login is expected to atleast return a username on the LoginInfo for logging purposes.
	Login(ctx *gin.Context, session *sessions.Session) (*LoginInfo, error)

	// Verify pulls the information Login put on the session and checks that those credentials are still valid
	// this should mainly be used in verifying established UI connections
	Verify(ctx *gin.Context, session *sessions.Session) error

	// Middleware authenticates a user that is directly using the REST endpoints. Nothing needs to be saved on the session for this function.
	// once there is verification that the user is authenticated, authenticatedKey should be set to "true" on the context
	// It is expected that loginID is set on the context to be used by the check user middleware. if the display name is different than the loginID, set usernameKey.
	Middleware() gin.HandlerFunc
}

Authenticator represents a way to authenticate a given username and password

func NewBasicAuthenticator

func NewBasicAuthenticator(username, password string) Authenticator

NewBasicAuthenticator creates an authenticator for internal server profile

type BasicAuthenticator

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

BasicAuthenticator is an authenticator that uses the server profile username and password

func (*BasicAuthenticator) Login

func (a *BasicAuthenticator) Login(c *gin.Context, session *sessions.Session) (*LoginInfo, error)

Login attempts to login in a user from the postform and returns the proper loginID

func (*BasicAuthenticator) Middleware

func (a *BasicAuthenticator) Middleware() gin.HandlerFunc

Middleware returns Authentication middleware for Basic server profile verification

func (*BasicAuthenticator) Verify

func (a *BasicAuthenticator) Verify(c *gin.Context, session *sessions.Session) error

Verify attempts to login in the user from the session

type LoginInfo

type LoginInfo struct {
	LoginID  string
	Username string
}

LoginInfo is a representation of user that has logged in.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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