auth

package
v0.35.18 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package auth provides the authentication abstraction for SpeechKit.

In OSS mode: no auth provider is registered, all auth functions return nil/false. Optional downstream products can register an AuthProvider via init(). The OSS core does not require a Kombify account, device-code login, or private auth package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasAuthProvider

func HasAuthProvider() bool

HasAuthProvider returns true if an auth provider has been registered.

func RegisterAuthProvider

func RegisterAuthProvider(p AuthProvider)

RegisterAuthProvider is called from init() in external product modules.

Types

type AuthProvider

type AuthProvider interface {
	// StartDeviceCodeFlow initiates the OAuth 2.0 Device Code flow.
	StartDeviceCodeFlow(ctx context.Context) (*DeviceCodeResponse, error)

	// PollDeviceCode checks if the user has completed browser authorization.
	// Returns ErrAuthorizationPending if the user hasn't authorized yet.
	PollDeviceCode(ctx context.Context, deviceCode string) (*TokenPair, error)

	// GetAccessToken returns a valid access token, refreshing if necessary.
	GetAccessToken(ctx context.Context) (string, error)

	// GetIdentity returns the current authenticated user's identity.
	GetIdentity(ctx context.Context) (*Identity, error)

	// Logout clears stored tokens.
	Logout(ctx context.Context) error

	// IsLoggedIn returns true if the user has a valid (or refreshable) token.
	IsLoggedIn() bool
}

AuthProvider is the interface that auth backends must implement. OSS builds have no registered provider. Downstream product builds may register one via init().

func GetAuthProvider

func GetAuthProvider() AuthProvider

GetAuthProvider returns the registered auth provider, or nil in OSS mode.

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode      string `json:"deviceCode"`
	UserCode        string `json:"userCode"`
	VerificationURL string `json:"verificationUrl"`
	ExpiresIn       int    `json:"expiresIn"`
	PollInterval    int    `json:"pollInterval"`
}

DeviceCodeResponse is returned when initiating a device code login flow.

type Identity

type Identity struct {
	UserID    string    `json:"userId"`
	OrgID     string    `json:"orgId"`
	Email     string    `json:"email"`
	Roles     []string  `json:"roles"`
	Plan      string    `json:"plan"`
	ExpiresAt time.Time `json:"expiresAt"`
}

Identity represents an authenticated user.

type TokenPair

type TokenPair struct {
	AccessToken  string    `json:"accessToken"`
	RefreshToken string    `json:"refreshToken"`
	ExpiresAt    time.Time `json:"expiresAt"`
	UserID       string    `json:"userId"`
}

TokenPair holds access + refresh tokens from a successful auth exchange.

Jump to

Keyboard shortcuts

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