Documentation ¶
Index ¶
- Variables
- func AuthenticateUserOrApp(ctx context.Context) error
- func BearerTokenAuthFunction(source Source) func(context.Context) (context.Context, error)
- func SetupContextWithAuthorization(ctx context.Context, token string) context.Context
- type AuthenticatedAppData
- type AuthenticatedUserData
- type BaseAuthSource
- type ContextAuthenticationKey
- type Database
- type Source
- type UnAuthenticatedContext
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnauthenticated = status.Error(codes.Unauthenticated, "Unauthenticated")
)
Functions ¶
func AuthenticateUserOrApp ¶
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 ¶
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.
Types ¶
type AuthenticatedAppData ¶
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 ¶
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