meta

package
v7.3.8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package meta provides authentication and token management for Meta Muse (api.meta.ai). It implements the RFC 8628 OAuth2 Device Authorization Grant flow for Meta accounts.

Index

Constants

View Source
const (
	// DefaultAPIBaseURL is the default official Meta API base URL.
	DefaultAPIBaseURL = "https://api.meta.ai/v1"
	// AuthHost is the Meta account OAuth authorization server.
	AuthHost = "https://auth.meta.com"
	// DeviceAuthorizationEndpoint is the device authorization request endpoint.
	DeviceAuthorizationEndpoint = AuthHost + "/oidc/device/authorization/"
	// TokenEndpoint is the token issuance and polling endpoint.
	TokenEndpoint = AuthHost + "/oidc/device/token/"
	// ClientID is Meta Muse CLI's official OAuth client ID.
	ClientID = "1031625952748946"
	// DeviceCodeGrantType is the RFC 8628 grant type parameter.
	DeviceCodeGrantType = "urn:ietf:params:oauth:grant-type:device_code"
	// DefaultPollInterval is the default polling interval when unspecified.
	DefaultPollInterval = 5 * time.Second
	// MaxPollDuration is the upper bound for waiting on user authorization.
	MaxPollDuration = 15 * time.Minute
)

Variables

This section is empty.

Functions

func CredentialFileName

func CredentialFileName(email, sub string) string

CredentialFileName keeps a readable account name and hashes the original identity so distinct emails that sanitize identically cannot overwrite each other.

Types

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
	TokenEndpoint           string `json:"-"`
}

DeviceCodeResponse represents Meta's device authorization response.

type MetaAuth

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

MetaAuth manages Meta OAuth operations.

func NewMetaAuth

func NewMetaAuth(cfg *config.Config) *MetaAuth

NewMetaAuth creates a new MetaAuth service instance.

func NewMetaAuthWithProxyURL

func NewMetaAuthWithProxyURL(cfg *config.Config, proxyURL string) *MetaAuth

NewMetaAuthWithProxyURL creates a MetaAuth service instance with an optional proxy URL.

func (*MetaAuth) CreateTokenStorage

func (a *MetaAuth) CreateTokenStorage(bundle *MetaAuthBundle) *MetaTokenStorage

CreateTokenStorage creates a serializable token storage record from the auth bundle.

func (*MetaAuth) MintAPIKey

func (a *MetaAuth) MintAPIKey(ctx context.Context, dcaToken string) (*MintedKeyResponse, error)

MintAPIKey exchanges a Device Client Access token (dca:...) for an LLM API key via https://api.meta.ai/muse-code/key.

func (*MetaAuth) SetMintURL

func (a *MetaAuth) SetMintURL(u string)

SetMintURL overrides the API key minting endpoint (primarily for unit tests).

func (*MetaAuth) StartDeviceFlow

func (a *MetaAuth) StartDeviceFlow(ctx context.Context) (*DeviceCodeResponse, error)

StartDeviceFlow initiates the device authorization flow with Meta.

func (*MetaAuth) StartDeviceFlowWithEndpoint

func (a *MetaAuth) StartDeviceFlowWithEndpoint(ctx context.Context, endpoint string) (*DeviceCodeResponse, error)

StartDeviceFlowWithEndpoint initiates the device authorization flow against a specific endpoint.

func (*MetaAuth) WaitForAuthorization

func (a *MetaAuth) WaitForAuthorization(ctx context.Context, dcr *DeviceCodeResponse) (*MetaAuthBundle, error)

WaitForAuthorization polls the token endpoint until the user approves the device code.

type MetaAuthBundle

type MetaAuthBundle struct {
	TokenData *TokenData
	MintedKey *MintedKeyResponse
	Email     string
	Name      string
}

MetaAuthBundle packages the token data, minted key, and user metadata.

type MetaTokenStorage

type MetaTokenStorage struct {
	Type         string `json:"type"`
	AuthKind     string `json:"auth_kind"`
	AccessToken  string `json:"access_token"`
	DCAToken     string `json:"dca_token,omitempty"`
	APIKey       string `json:"api_key,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Expired      string `json:"expired,omitempty"`
	DCAExpired   string `json:"dca_expired,omitempty"`
	DCAExpiresAt int64  `json:"dca_expires_at,omitempty"`
	LastRefresh  string `json:"last_refresh,omitempty"`
	BaseURL      string `json:"base_url,omitempty"`
	Email        string `json:"email,omitempty"`
	Name         string `json:"name,omitempty"`

	Metadata map[string]any `json:"-"`
}

MetaTokenStorage represents persisted Meta OAuth tokens in auth files.

func (*MetaTokenStorage) SaveTokenToFile

func (ts *MetaTokenStorage) SaveTokenToFile(authFilePath string) error

SaveTokenToFile writes Meta credentials to a JSON auth file.

func (*MetaTokenStorage) SetMetadata

func (ts *MetaTokenStorage) SetMetadata(meta map[string]any)

SetMetadata allows the token store to merge status fields before saving.

type MintedKeyResponse

type MintedKeyResponse struct {
	APIKey           string `json:"api_key"`
	BaseURL          string `json:"base_url"`
	UserEmail        string `json:"user_email"`
	UserFullName     string `json:"user_full_name"`
	SubsTierName     string `json:"subs_tier_name"`
	SubsTierID       string `json:"subs_tier_id"`
	IsSubsActive     bool   `json:"is_subs_active"`
	HasPaymentMethod bool   `json:"has_payment_method"`
	RequirePayment   bool   `json:"require_payment"`
	CanSubscribe     bool   `json:"can_subscribe"`
}

MintedKeyResponse represents the API key response minted from https://api.meta.ai/muse-code/key.

type TokenData

type TokenData struct {
	AccessToken      string `json:"access_token"`
	TokenType        string `json:"token_type"`
	ExpiresIn        int    `json:"expires_in,omitempty"`
	ExpiresAt        int64  `json:"expires_at,omitempty"`
	Error            string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
}

TokenData represents the token response from Meta's OAuth token endpoint.

Jump to

Keyboard shortcuts

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