reworked api interfaces

This commit is contained in:
2025-09-22 16:41:49 -07:00
parent f2256a9cfe
commit 1b3fb04dcd
44 changed files with 1356 additions and 207 deletions

View File

@@ -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)
}