jauth

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const TokenClaimsContextKey = "jauth.jwt_claims"

Variables

View Source
var (
	ErrInvalidSocialProvider         = errors.New("invalid social provider")
	ErrSocialLoginAttemptNotFound    = errors.New("social login attempt not found")
	ErrSocialLoginAttemptUnavailable = errors.New("social login attempt unavailable")
)

Functions

func BoolClaim

func BoolClaim(claims Claims, key string) (bool, bool)

func GenerateSocialLoginNonce

func GenerateSocialLoginNonce() (string, string, error)

func GenerateToken

func GenerateToken(ctx context.Context, claims Claims) (string, error)

func HTTPStatus

func HTTPStatus(err error) int

func IsCode

func IsCode(err error, code ErrorCode) bool

func JWTAuth

func JWTAuth() gin.HandlerFunc

func Module

func Module() jelly.Module

func StringClaim

func StringClaim(claims Claims, key string) (string, bool)

func StringSliceClaim

func StringSliceClaim(claims Claims, key string) ([]string, bool)

Types

type AuthenticationCredential

type AuthenticationCredential struct {
	ID                      string                 `json:"id"`
	RawID                   string                 `json:"rawId"`
	Type                    string                 `json:"type"`
	AuthenticatorAttachment string                 `json:"authenticatorAttachment,omitempty"`
	Response                AuthenticationResponse `json:"response"`
	ClientExtensionResults  map[string]any         `json:"clientExtensionResults,omitempty"`
}

func ParseAuthenticationCredential

func ParseAuthenticationCredential(data []byte) (*AuthenticationCredential, error)

type AuthenticationLookup

type AuthenticationLookup struct {
	CredentialID []byte `json:"credential_id"`
	UserHandle   string `json:"user_handle,omitempty"`
}

func LookupAuthenticationCredential

func LookupAuthenticationCredential(ctx context.Context, credential AuthenticationCredential) (*AuthenticationLookup, error)

type AuthenticationOptions

type AuthenticationOptions struct {
	PublicKey     map[string]any `json:"public_key"`
	CeremonyState string         `json:"ceremony_state"`
	ExpiresAt     time.Time      `json:"expires_at"`
}

type AuthenticationRequest

type AuthenticationRequest struct {
	UserID             string                      `json:"user_id,omitempty"`
	AllowedCredentials []CredentialDescriptor      `json:"allowed_credentials,omitempty"`
	UserVerification   UserVerificationRequirement `json:"user_verification,omitempty"`
}

type AuthenticationResponse

type AuthenticationResponse struct {
	ClientDataJSON    string `json:"clientDataJSON"`
	AuthenticatorData string `json:"authenticatorData"`
	Signature         string `json:"signature"`
	UserHandle        string `json:"userHandle,omitempty"`
}

type AuthenticationResult

type AuthenticationResult struct {
	CredentialID []byte `json:"credential_id"`
	NewSignCount uint32 `json:"new_sign_count"`
	UserID       string `json:"user_id,omitempty"`
	UserHandle   string `json:"user_handle,omitempty"`
	CloneWarning bool   `json:"clone_warning,omitempty"`
}

type AuthenticationVerificationRequest

type AuthenticationVerificationRequest struct {
	CeremonyState string                   `json:"ceremony_state"`
	Credential    AuthenticationCredential `json:"credential"`
	Credentials   []StoredCredential       `json:"credentials"`
}

type AuthenticatorAttachment

type AuthenticatorAttachment string
const (
	AttachmentPlatform      AuthenticatorAttachment = "platform"
	AttachmentCrossPlatform AuthenticatorAttachment = "cross-platform"
)

type Claims

type Claims map[string]any

func ParseToken

func ParseToken(ctx context.Context, token string) (Claims, error)

func TokenClaims

func TokenClaims(c *gin.Context) (Claims, bool)

type CompleteSocialLoginInput

type CompleteSocialLoginInput struct {
	Provider  SocialProvider
	AttemptID string
	IDToken   string
	Now       time.Time
}

type CompleteSocialLoginResult

type CompleteSocialLoginResult struct {
	Identity Identity
	Attempt  SocialLoginAttempt
}

type Config

type Config struct {
	JWT     *JWTConfig     `yaml:"jwt"`
	OIDC    *OIDCConfig    `yaml:"oidc"`
	Passkey *PasskeyConfig `yaml:"passkey,omitempty"`
}

func DefaultConfig

func DefaultConfig() Config

type CredentialDescriptor

type CredentialDescriptor struct {
	CredentialID []byte                `json:"credential_id"`
	Transports   []CredentialTransport `json:"transports,omitempty"`
}

type CredentialFlags

type CredentialFlags struct {
	UserPresent    bool `json:"user_present"`
	UserVerified   bool `json:"user_verified"`
	BackupEligible bool `json:"backup_eligible"`
	BackupState    bool `json:"backup_state"`
}

type CredentialTransport

type CredentialTransport string

type Error

type Error struct {
	Code    ErrorCode
	Message string
	Cause   error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	ErrCodeNotConfigured         ErrorCode = "not_configured"
	ErrCodeInvalidConfig         ErrorCode = "invalid_config"
	ErrCodeInvalidCeremonyState  ErrorCode = "invalid_ceremony_state"
	ErrCodeInvalidCredential     ErrorCode = "invalid_credential"
	ErrCodeInvalidChallenge      ErrorCode = "invalid_challenge"
	ErrCodeInvalidOrExpiredState ErrorCode = "invalid_or_expired_ceremony_state"
	ErrCodeInvalidOrigin         ErrorCode = "invalid_origin"
	ErrCodeInvalidRPID           ErrorCode = "invalid_rp_id"
	ErrCodeUserVerification      ErrorCode = "user_verification_required"
	ErrCodeCredentialNotFound    ErrorCode = "credential_not_found"
)

type Identity

type Identity struct {
	Provider      string `json:"provider"`
	Subject       string `json:"subject"`
	Email         string `json:"email,omitempty"`
	Name          string `json:"name,omitempty"`
	EmailVerified bool   `json:"emailVerified"`
}

func VerifyAppleIDToken

func VerifyAppleIDToken(ctx context.Context, idToken string) (Identity, error)

func VerifyAppleIDTokenWithOptions

func VerifyAppleIDTokenWithOptions(ctx context.Context, idToken string, opts VerifyIDTokenOptions) (Identity, error)

func VerifyGoogleIDToken

func VerifyGoogleIDToken(ctx context.Context, idToken string) (Identity, error)

func VerifyGoogleIDTokenWithOptions

func VerifyGoogleIDTokenWithOptions(ctx context.Context, idToken string, opts VerifyIDTokenOptions) (Identity, error)

type JWTConfig

type JWTConfig struct {
	Secret string `yaml:"secret"`
	Issuer string `yaml:"issuer"`
	TTL    string `yaml:"access-ttl"`
}

type OIDCConfig

type OIDCConfig struct {
	Google *OIDCProviderConfig `yaml:"google"`
	Apple  *OIDCProviderConfig `yaml:"apple"`
}

type OIDCProviderConfig

type OIDCProviderConfig struct {
	ClientID string `yaml:"client-id"`
}

type PasskeyConfig

type PasskeyConfig struct {
	RPID        string   `yaml:"rp-id"`
	RPName      string   `yaml:"rp-name"`
	Origins     []string `yaml:"origins"`
	StateSecret string   `yaml:"state-secret"`
}

type RegistrationCredential

type RegistrationCredential struct {
	ID                      string               `json:"id"`
	RawID                   string               `json:"rawId"`
	Type                    string               `json:"type"`
	AuthenticatorAttachment string               `json:"authenticatorAttachment,omitempty"`
	Response                RegistrationResponse `json:"response"`
	ClientExtensionResults  map[string]any       `json:"clientExtensionResults,omitempty"`
}

func ParseRegistrationCredential

func ParseRegistrationCredential(data []byte) (*RegistrationCredential, error)

type RegistrationOptions

type RegistrationOptions struct {
	PublicKey     map[string]any `json:"public_key"`
	CeremonyState string         `json:"ceremony_state"`
	ExpiresAt     time.Time      `json:"expires_at"`
}

func BuildRegistrationOptions

func BuildRegistrationOptions(ctx context.Context, req RegistrationRequest) (*RegistrationOptions, error)

type RegistrationRequest

type RegistrationRequest struct {
	User                    RegistrationUser            `json:"user"`
	ExcludeCredentials      []CredentialDescriptor      `json:"exclude_credentials,omitempty"`
	ResidentKey             ResidentKeyRequirement      `json:"resident_key,omitempty"`
	UserVerification        UserVerificationRequirement `json:"user_verification,omitempty"`
	AuthenticatorAttachment AuthenticatorAttachment     `json:"authenticator_attachment,omitempty"`
}

type RegistrationResponse

type RegistrationResponse struct {
	ClientDataJSON     string                `json:"clientDataJSON"`
	AttestationObject  string                `json:"attestationObject"`
	Transports         []CredentialTransport `json:"transports,omitempty"`
	PublicKey          string                `json:"publicKey,omitempty"`
	PublicKeyAlgorithm int                   `json:"publicKeyAlgorithm,omitempty"`
	AuthenticatorData  string                `json:"authenticatorData,omitempty"`
}

type RegistrationResult

type RegistrationResult struct {
	CredentialID            []byte                `json:"credential_id"`
	PublicKey               []byte                `json:"public_key"`
	SignCount               uint32                `json:"sign_count"`
	AAGUID                  string                `json:"aaguid"`
	AuthenticatorAttachment string                `json:"authenticator_attachment"`
	AttestationType         string                `json:"attestation_type,omitempty"`
	Transports              []CredentialTransport `json:"transports,omitempty"`
	Flags                   CredentialFlags       `json:"flags,omitempty"`
}

func VerifyRegistration

func VerifyRegistration(ctx context.Context, ceremonyState string, credential RegistrationCredential) (*RegistrationResult, error)

type RegistrationUser

type RegistrationUser struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

type ResidentKeyRequirement

type ResidentKeyRequirement string
const (
	ResidentKeyRequired    ResidentKeyRequirement = "required"
	ResidentKeyPreferred   ResidentKeyRequirement = "preferred"
	ResidentKeyDiscouraged ResidentKeyRequirement = "discouraged"
)

type SocialLoginAttempt

type SocialLoginAttempt struct {
	ID          string
	Provider    SocialProvider
	Nonce       string
	NonceSHA256 string
	CreatedAt   time.Time
	ExpiresAt   time.Time
	ConsumedAt  *time.Time
}

type SocialLoginAttemptStore

type SocialLoginAttemptStore interface {
	CreateSocialLoginAttempt(ctx context.Context, attempt SocialLoginAttempt) error
	GetSocialLoginAttempt(ctx context.Context, provider SocialProvider, attemptID string) (*SocialLoginAttempt, error)
	ConsumeSocialLoginAttempt(ctx context.Context, provider SocialProvider, attemptID string, now time.Time) (bool, error)
}

type SocialProvider

type SocialProvider string
const (
	SocialProviderGoogle SocialProvider = "google"
	SocialProviderApple  SocialProvider = "apple"
)

type StartSocialLoginInput

type StartSocialLoginInput struct {
	Provider SocialProvider
	Now      time.Time
}

type StartSocialLoginResult

type StartSocialLoginResult struct {
	AttemptID   string         `json:"attempt_id"`
	Provider    SocialProvider `json:"provider"`
	Nonce       string         `json:"nonce"`
	NonceSHA256 string         `json:"nonce_sha256"`
	ExpiresAt   time.Time      `json:"expires_at"`
}

type StoredCredential

type StoredCredential struct {
	UserID                  string                `json:"user_id"`
	CredentialID            []byte                `json:"credential_id"`
	PublicKey               []byte                `json:"public_key"`
	SignCount               uint32                `json:"sign_count"`
	AAGUID                  string                `json:"aaguid,omitempty"`
	AuthenticatorAttachment string                `json:"authenticator_attachment,omitempty"`
	AttestationType         string                `json:"attestation_type,omitempty"`
	Transports              []CredentialTransport `json:"transports,omitempty"`
	Flags                   CredentialFlags       `json:"flags,omitempty"`
}

type UserVerificationRequirement

type UserVerificationRequirement string
const (
	UserVerificationRequired    UserVerificationRequirement = "required"
	UserVerificationPreferred   UserVerificationRequirement = "preferred"
	UserVerificationDiscouraged UserVerificationRequirement = "discouraged"
)

type VerifyIDTokenOptions

type VerifyIDTokenOptions struct {
	Nonce         string
	AllowedNonces []string
}

Jump to

Keyboard shortcuts

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