idp

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ApiKeyPrefix = "fancyspaces_api_key"
View Source
const ServiceName = "fancyanalytics-idp"

Variables

View Source
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")
)
View Source
var ServiceBaseURL = "https://fancyanalytics.net/idp/api/v1"
View Source
var SigningMethod = jwt.SigningMethodRS256

Functions

func AccountDisabledProblem

func AccountDisabledProblem() *problems.Problem

func AccountNotVerifiedProblem

func AccountNotVerifiedProblem() *problems.Problem

func CheckPassword added in v0.0.2

func CheckPassword(password, stored string) (bool, error)

func IsUserValid

func IsUserValid(user *User) bool

IsUserValid checks if the user is valid for authentication or authorization purposes.

func PasswordHash

func PasswordHash(password string) string

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 Provider

type Provider string
const (
	ProviderBasic   Provider = "basic"
	ProviderGoogle  Provider = "google"
	ProviderGithub  Provider = "github"
	ProviderDiscord Provider = "discord"
)

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) GetUser

func (s *Service) GetUser(id string) (*User, error)

GetUser retrieves a user by their ID or email.

func (*Service) HTTPMiddleware

func (s *Service) HTTPMiddleware(next http.Handler) http.Handler

func (*Service) ValidateApiKey added in v0.0.5

func (s *Service) ValidateApiKey(apiKeyStr string) (*User, error)

func (*Service) ValidateToken

func (s *Service) ValidateToken(token string) (*User, error)

ValidateToken validates the provided JWT token string and returns the associated user if the token is valid.

func (*Service) ValidateUser

func (s *Service) ValidateUser(userID, password string) (*User, error)

ValidateUser validates a user's credentials and returns the user if 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

func UserFromCtx(ctx context.Context) *User

UserFromCtx retrieves the user from the context. It returns nil if no user is found.

func (*User) IsAdmin

func (u *User) IsAdmin() bool

Jump to

Keyboard shortcuts

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