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
- func BuildOAuthMetadata(storage *MetaTokenStorage) map[string]any
- func CredentialFileName(email, sub string) string
- type DeviceCodeResponse
- type MetaAuth
- func (a *MetaAuth) CreateTokenStorage(bundle *MetaAuthBundle) *MetaTokenStorage
- func (a *MetaAuth) MintAPIKey(ctx context.Context, dcaToken string) (*MintedKeyResponse, error)
- func (a *MetaAuth) StartDeviceFlow(ctx context.Context) (*DeviceCodeResponse, error)
- func (a *MetaAuth) WaitForAuthorization(ctx context.Context, dcr *DeviceCodeResponse) (*MetaAuthBundle, error)
- type MetaAuthBundle
- type MetaTokenStorage
- type MintedKeyResponse
- type TokenData
Constants ¶
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 BuildOAuthMetadata ¶
func BuildOAuthMetadata(storage *MetaTokenStorage) map[string]any
BuildOAuthMetadata builds the persisted Meta OAuth credential metadata.
func CredentialFileName ¶
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 ¶
NewMetaAuth creates a new MetaAuth service instance.
func NewMetaAuthWithProxyURL ¶
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 ¶
MintAPIKey exchanges a Device Client Access token for an LLM API key.
func (*MetaAuth) StartDeviceFlow ¶
func (a *MetaAuth) StartDeviceFlow(ctx context.Context) (*DeviceCodeResponse, error)
StartDeviceFlow initiates the device authorization flow with Meta.
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
AuthKind string
AccessToken string
DCAToken string
APIKey string
TokenType string
ExpiresIn int
Expired string
DCAExpired string
DCAExpiresAt int64
LastRefresh string
BaseURL string
Email string
Name string
}
MetaTokenStorage represents persisted Meta OAuth tokens.
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"`
}
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.