auth

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package auth issues and verifies generic lobby guest credentials. It performs no environment reads, database setup, or HTTP registration.

Index

Constants

View Source
const GoogleCertsURL = "https://www.googleapis.com/oauth2/v3/certs"

GoogleCertsURL publishes the keys that sign Google's ID tokens.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accounts added in v0.6.0

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

Accounts signs people in with Google and manages the account of a signed-in session. A sign-in opens a session as a guest session does, of a new player that belongs to the account.

func NewAccounts added in v0.6.0

func NewAccounts(sessions *Service, store domain.AccountStore, verifier IDTokenVerifier, googleClientID string) (*Accounts, error)

NewAccounts manages accounts in store and opens their sessions with sessions. verifier checks Google ID tokens for googleClientID, the client ID that sign-in buttons use; a nil verifier turns sign-in off.

func (*Accounts) Account added in v0.6.0

func (accounts *Accounts) Account(ctx context.Context, principal domain.Principal) (domain.Account, error)

func (*Accounts) DeleteAccount added in v0.6.0

func (accounts *Accounts) DeleteAccount(ctx context.Context, principal domain.Principal) error

func (*Accounts) RenameAccount added in v0.6.0

func (accounts *Accounts) RenameAccount(ctx context.Context, principal domain.Principal, displayName string) (domain.Account, error)

func (*Accounts) SignInSettings added in v0.6.0

func (accounts *Accounts) SignInSettings() domain.SignInSettings

func (*Accounts) SignInWithGoogle added in v0.6.0

func (accounts *Accounts) SignInWithGoogle(ctx context.Context, request domain.SignInRequest) (domain.AccountSession, error)

type GoogleVerifier added in v0.6.0

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

GoogleVerifier verifies Google ID tokens: an RS256 signature by one of the keys at CertsURL, which it caches as their Cache-Control says, an iss of Google's, an aud that is one of ClientIDs, and an exp in the future. It trusts no claim but sub.

func NewGoogleVerifier added in v0.6.0

func NewGoogleVerifier(clientIDs []string, certsURL string, client *http.Client, clock domain.Clock) (*GoogleVerifier, error)

NewGoogleVerifier verifies the ID tokens of clientIDs with the keys at certsURL, GoogleCertsURL in production. A nil client is http.DefaultClient.

func (*GoogleVerifier) Verify added in v0.6.0

func (verifier *GoogleVerifier) Verify(ctx context.Context, token string) (string, error)

type IDTokenVerifier added in v0.6.0

type IDTokenVerifier interface {
	Verify(ctx context.Context, token string) (subject string, err error)
}

IDTokenVerifier checks an identity provider's ID token and returns its subject, the provider's ID of the account. An invalid token is domain.ErrUnauthenticated; keys that can't be fetched are domain.ErrUnavailable.

type PlayerTokens

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

PlayerTokens issues the player tokens that games verify with the lobby's public keys, and publishes those keys.

func NewPlayerTokens

func NewPlayerTokens(keys *playertoken.KeySet, issuer string, lifetime time.Duration, clock domain.Clock, policy domain.Policy) (*PlayerTokens, error)

NewPlayerTokens signs with keys as issuer, the lobby's public URL, for the games of policy. A token lasts lifetime, at most playertoken.MaxLifetime, and never past its session.

func (*PlayerTokens) IssuePlayerToken

func (tokens *PlayerTokens) IssuePlayerToken(ctx context.Context, verification domain.SessionVerification, gameKey string) (domain.PlayerToken, error)

IssuePlayerToken signs a token for the session's player and gameKey. The token expires after the lifetime or with the session, whichever comes first. An unknown game is ErrNotFound.

func (*PlayerTokens) PublicKeys

func (tokens *PlayerTokens) PublicKeys() playertoken.JWKS

PublicKeys is the JWKS of every key: the one that signs, and any previous ones.

type Service

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

Service implements both the Authenticator and ConnectionTokenIssuer ports. Its dependencies are injected so bootstrap selects secrets and production I/O.

func NewService

func NewService(
	identities domain.IdentityStore,
	clock domain.Clock,
	policy domain.Policy,
	identifiers domain.IdentifierSource,
	signingSecret []byte,
	publicWebsocketURL string,
) (*Service, error)

NewService validates all configuration required for guest credentials and Centrifugo connection JWTs. The secret is copied before retaining it.

func (*Service) Authenticate

func (service *Service) Authenticate(ctx context.Context, authorization string) (domain.SessionVerification, error)

func (*Service) CreateGuest

func (service *Service) CreateGuest(ctx context.Context, request domain.CreateGuestRequest) (domain.GuestSession, error)

func (*Service) IssueConnectionToken

func (service *Service) IssueConnectionToken(ctx context.Context, verification domain.SessionVerification) (domain.ConnectionToken, error)

IssueConnectionToken rechecks the durable one-session identity before signing a short connection JWT. This prevents an arbitrary constructed verification value from becoming authority and creates no lobby-side state.

Directories

Path Synopsis
Package googletest signs ID tokens the way Google does, with a key of its own, for tests and live suites of Sign in with Google.
Package googletest signs ID tokens the way Google does, with a key of its own, for tests and live suites of Sign in with Google.

Jump to

Keyboard shortcuts

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