auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearToken

func ClearToken() error

ClearToken removes the authentication token from the OS credential manager

func IsAuthenticated

func IsAuthenticated() bool

IsAuthenticated checks if a valid token exists

func SaveToken

func SaveToken(token *AuthToken) error

SaveToken saves the authentication token to the OS credential manager

Types

type AuthToken

type AuthToken struct {
	// GitHub OAuth Token
	GitHubToken     string   `json:"github_token"`
	GitHubTokenType string   `json:"github_token_type"`
	GitHubScopes    []string `json:"github_scopes"`

	// MoMorph Platform Token
	MoMorphToken     string    `json:"momorph_token"`
	MoMorphExpiresAt time.Time `json:"momorph_expires_at"`

	// User Information
	Username  string `json:"username"`
	AvatarURL string `json:"avatar_url"`
	Email     string `json:"email"`
	UserID    string `json:"user_id"`

	// Metadata
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

AuthToken stores both GitHub OAuth token and MoMorph platform token

func LoadToken

func LoadToken() (*AuthToken, error)

LoadToken loads the authentication token from the OS credential manager

func (*AuthToken) IsValid

func (t *AuthToken) IsValid() bool

IsValid checks if the MoMorph token is still valid

func (*AuthToken) NeedsRefresh

func (t *AuthToken) NeedsRefresh() bool

NeedsRefresh checks if the token needs refresh (expires within 24 hours)

type DeviceCodeResponse

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

DeviceCodeResponse represents GitHub's device code response

func RequestDeviceCode

func RequestDeviceCode(ctx context.Context) (*DeviceCodeResponse, error)

RequestDeviceCode requests a device code from GitHub

type GitHubUser

type GitHubUser struct {
	Login     string `json:"login"`
	ID        int    `json:"id"`
	AvatarURL string `json:"avatar_url"`
	Name      string `json:"name"`
	Email     string `json:"email"`
}

GitHubUser represents a GitHub user

func GetAuthenticatedUser

func GetAuthenticatedUser(ctx context.Context, accessToken string) (*GitHubUser, error)

GetAuthenticatedUser retrieves the authenticated user's information from GitHub

type MoMorphTokenResponse

type MoMorphTokenResponse struct {
	Token string `json:"token"`
}

MoMorphTokenResponse represents the response from MoMorph token exchange

func ExchangeGitHubToken

func ExchangeGitHubToken(ctx context.Context, githubToken string) (*MoMorphTokenResponse, error)

ExchangeGitHubToken exchanges a GitHub OAuth token for a MoMorph platform token

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
	Error       string `json:"error"`
	ErrorDesc   string `json:"error_description"`
}

TokenResponse represents GitHub's token response

func PollForToken

func PollForToken(ctx context.Context, deviceCode string, interval int) (*TokenResponse, error)

PollForToken polls GitHub for the access token

Jump to

Keyboard shortcuts

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