authentication

package
v0.0.0-...-eec4b17 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = status.Error(codes.Unauthenticated, "Unauthenticated")
)

Functions

func AuthenticateUserOrApp

func AuthenticateUserOrApp(ctx context.Context) error

AuthenticateUserOrApp checks if the given context contains either an authenticated user or an authenticated app. If so, it returns nil, otherwise it returns an error.

func BearerTokenAuthFunction

func BearerTokenAuthFunction(source Source) func(context.Context) (context.Context, error)

BearerTokenAuthFunction returns a function that checks whether the given context.Context object contains the metadata related to authentication. Based on the metadata supplied within the context, it returns either one of the three context implementations: UnAuthenticatedContext, AuthenticatedUserData or AuthenticatedAppData.

func SetupContextWithAuthorization

func SetupContextWithAuthorization(ctx context.Context, token string) context.Context

SetupContextWithAuthorization setups the given context to properly include the given token as the authorization header's value

Types

type AuthenticatedAppData

type AuthenticatedAppData struct {
	Token string
	AppID string
}

AuthenticatedAppData contains the data of an authenticated application

func GetAuthenticatedAppData

func GetAuthenticatedAppData(ctx context.Context) (*AuthenticatedAppData, error)

GetAuthenticatedAppData returns the authenticated app data from the given context. If the app is not authenticated, an error is returned instead.

type AuthenticatedUserData

type AuthenticatedUserData struct {
	Token         string
	DesmosAddress string
}

AuthenticatedUserData contains the data of an authenticated user

func GetAuthenticatedUserData

func GetAuthenticatedUserData(ctx context.Context) (*AuthenticatedUserData, error)

GetAuthenticatedUserData returns the authenticated user data from the given context. If the user is not authenticated, an error is returned instead.

type BaseAuthSource

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

BaseAuthSource represents a basic implementation for the Source interface

func NewBaseAuthSource

func NewBaseAuthSource(db Database) *BaseAuthSource

func (*BaseAuthSource) GetAppToken

func (s *BaseAuthSource) GetAppToken(token string) (*types.EncryptedAppToken, error)

GetAppToken implements authentication.Source

func (*BaseAuthSource) GetUserSession

func (s *BaseAuthSource) GetUserSession(token string) (*types.EncryptedUserSession, error)

GetUserSession implements authentication.Source

type ContextAuthenticationKey

type ContextAuthenticationKey string
var (
	DataKey ContextAuthenticationKey = "AuthenticationData"
)

type Database

type Database interface {
	SaveSession(session *types.UserSession) error
	GetUserSession(token string) (*types.EncryptedUserSession, error)
	UpdateSession(session *types.EncryptedUserSession) error
	DeleteSession(token string) error

	GetAppToken(token string) (*types.EncryptedAppToken, error)
}

Database represents the interface that must be implemented in order to properly read the data required during the authentication processes

type Source

type Source interface {

	// GetUserSession returns the user session associated to the given token
	// or an error if something goes wrong
	GetUserSession(token string) (*types.EncryptedUserSession, error)

	// GetAppToken returns the app session associated to the given token
	// or an error if something goes wrong
	GetAppToken(token string) (*types.EncryptedAppToken, error)
	// contains filtered or unexported methods
}

Source represents the interface that must be implemented in order to get the encrypted session of a user

type UnAuthenticatedContext

type UnAuthenticatedContext struct {
}

UnAuthenticatedContext represents the gRPC context that will be used when the user is not authenticated

Jump to

Keyboard shortcuts

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