Documentation
¶
Index ¶
- Constants
- Variables
- func AccountDisabledProblem() *problems.Problem
- func AccountNotVerifiedProblem() *problems.Problem
- func CheckPassword(password, stored string) (bool, error)
- func IsUserValid(user *User) bool
- func PasswordHash(password string) string
- type ApiKey
- type Configuration
- type Provider
- type Service
- func (s *Service) GetUser(id string) (*User, error)
- func (s *Service) HTTPMiddleware(next http.Handler) http.Handler
- func (s *Service) ValidateApiKey(apiKeyStr string) (*User, error)
- func (s *Service) ValidateToken(token string) (*User, error)
- func (s *Service) ValidateUser(userID, password string) (*User, error)
- type User
Constants ¶
const ApiKeyPrefix = "fancyspaces_api_key"
const ServiceName = "fancyanalytics-idp"
Variables ¶
var ( ErrMissingAuthorizationHeader = errors.New("missing Authorization header") ErrInvalidAuthenticationMethod = errors.New("invalid authentication method, expected Bearer or Basic") ErrInvalidTokenFormat = errors.New("invalid token format") ErrInvalidToken = errors.New("invalid token") ErrInvalidApiKeyFormat = errors.New("invalid API key format") ErrApiKeyNotFound = errors.New("API key not found") ErrInvalidApiKey = errors.New("invalid API key") ErrInvalidBasicCredentials = errors.New("invalid basic authentication credentials") ErrUserNotFound = errors.New("user not found") )
var ServiceBaseURL = "https://fancyanalytics.net/idp/api/v1"
var SigningMethod = jwt.SigningMethodRS256
Functions ¶
func AccountDisabledProblem ¶
func CheckPassword ¶ added in v0.0.2
func IsUserValid ¶
IsUserValid checks if the user is valid for authentication or authorization purposes.
func PasswordHash ¶
PasswordHash generates a secure hash for the given password using the Argon2 algorithm.
Types ¶
type ApiKey ¶ added in v0.0.5
type ApiKey struct {
KeyID string `json:"key_id" bson:"key_id"` // globally unique identifier for the API key
UserID string `json:"user_id" bson:"user_id"`
Description string `json:"description" bson:"description"`
Key string `json:"key" bson:"key"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty" bson:"last_used_at,omitempty"`
}
ApiKey represents an API key associated with a user.
type Configuration ¶
type Configuration struct {
// Broker is the message broker used for communication with the IDP service.
Broker broker.Broker
// PublicKey is the RSA public key used for validating JWT tokens issued by the IDP service.
PublicKey *rsa.PublicKey
}
Configuration holds the necessary configuration for initializing the IDP service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods to interact with the IDP service.
func NewService ¶
func NewService(cfg Configuration) *Service
NewService initializes and returns a new instance of the IDP service with the provided configuration.
func (*Service) ValidateApiKey ¶ added in v0.0.5
func (*Service) ValidateToken ¶
ValidateToken validates the provided JWT token string and returns the associated user if the token is valid.
type User ¶
type User struct {
ID string `json:"id" bson:"id"`
Provider Provider `json:"provider" bson:"provider"`
Name string `json:"name" bson:"name"`
Email string `json:"email" bson:"email"`
Verified bool `json:"verified" bson:"verified"`
Password string `json:"password" bson:"password"`
Roles []string `json:"roles" bson:"roles"` // e.g., ["admin", "user"]
CreatedAt time.Time `json:"created_at" bson:"created_at"`
IsActive bool `json:"is_active" bson:"is_active"`
Metadata map[string]string `json:"metadata" bson:"metadata"` // Additional user metadata
}
User represents a user in the identity provider system. The ID and Email fields are unique identifiers.
func UserFromCtx ¶
UserFromCtx retrieves the user from the context. It returns nil if no user is found.