mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-26 09:03:00 +00:00
reworked api interfaces
This commit is contained in:
@@ -9,12 +9,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sstent/go-garth/internal/models/types"
|
||||
"github.com/sstent/go-garth/internal/utils"
|
||||
garth "github.com/sstent/go-garth/pkg/garth/types"
|
||||
)
|
||||
|
||||
// GetOAuth1Token retrieves an OAuth1 token using the provided ticket
|
||||
func GetOAuth1Token(domain, ticket string) (*types.OAuth1Token, error) {
|
||||
func GetOAuth1Token(domain, ticket string) (*garth.OAuth1Token, error) {
|
||||
scheme := "https"
|
||||
if strings.HasPrefix(domain, "127.0.0.1") {
|
||||
scheme = "http"
|
||||
@@ -85,7 +85,7 @@ func GetOAuth1Token(domain, ticket string) (*types.OAuth1Token, error) {
|
||||
return nil, fmt.Errorf("missing oauth_token or oauth_token_secret in response")
|
||||
}
|
||||
|
||||
return &types.OAuth1Token{
|
||||
return &garth.OAuth1Token{
|
||||
OAuthToken: oauthToken,
|
||||
OAuthTokenSecret: oauthTokenSecret,
|
||||
MFAToken: values.Get("mfa_token"),
|
||||
@@ -94,7 +94,7 @@ func GetOAuth1Token(domain, ticket string) (*types.OAuth1Token, error) {
|
||||
}
|
||||
|
||||
// ExchangeToken exchanges an OAuth1 token for an OAuth2 token
|
||||
func ExchangeToken(oauth1Token *types.OAuth1Token) (*types.OAuth2Token, error) {
|
||||
func ExchangeToken(oauth1Token *garth.OAuth1Token) (*garth.OAuth2Token, error) {
|
||||
scheme := "https"
|
||||
if strings.HasPrefix(oauth1Token.Domain, "127.0.0.1") {
|
||||
scheme = "http"
|
||||
@@ -148,7 +148,7 @@ func ExchangeToken(oauth1Token *types.OAuth1Token) (*types.OAuth2Token, error) {
|
||||
return nil, fmt.Errorf("OAuth2 exchange failed with status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var oauth2Token types.OAuth2Token
|
||||
var oauth2Token garth.OAuth2Token
|
||||
if err := json.Unmarshal(body, &oauth2Token); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode OAuth2 token: %w", err)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sstent/go-garth/internal/auth/oauth"
|
||||
types "github.com/sstent/go-garth/internal/models/types"
|
||||
garth "github.com/sstent/go-garth/pkg/garth/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -41,7 +41,7 @@ func NewClient(domain string) *Client {
|
||||
}
|
||||
|
||||
// Login performs the SSO authentication flow
|
||||
func (c *Client) Login(email, password string) (*types.OAuth2Token, *MFAContext, error) {
|
||||
func (c *Client) Login(email, password string) (*garth.OAuth2Token, *MFAContext, error) {
|
||||
fmt.Printf("Logging in to Garmin Connect (%s) using SSO flow...\n", c.Domain)
|
||||
|
||||
scheme := "https"
|
||||
@@ -185,7 +185,7 @@ func (c *Client) Login(email, password string) (*types.OAuth2Token, *MFAContext,
|
||||
}
|
||||
|
||||
// ResumeLogin completes authentication after MFA challenge
|
||||
func (c *Client) ResumeLogin(mfaCode string, ctx *MFAContext) (*types.OAuth2Token, error) {
|
||||
func (c *Client) ResumeLogin(mfaCode string, ctx *MFAContext) (*garth.OAuth2Token, error) {
|
||||
fmt.Println("Resuming login with MFA code...")
|
||||
|
||||
// Submit MFA form
|
||||
|
||||
Reference in New Issue
Block a user