Files
go-garminconnect/internal/auth/compat.go
2025-08-28 09:58:24 -07:00

34 lines
835 B
Go

package auth
import (
"fmt"
"github.com/sstent/go-garminconnect/internal/auth/garth"
)
// LegacyAuthToGarth converts a legacy authentication token to a garth session
func LegacyAuthToGarth(legacyToken *Token) (*garth.Session, error) {
if legacyToken == nil {
return nil, fmt.Errorf("legacy token cannot be nil")
}
return &garth.Session{
OAuth1Token: legacyToken.OAuthToken,
OAuth1Secret: legacyToken.OAuthSecret,
OAuth2Token: legacyToken.AccessToken,
}, nil
}
// GarthToLegacyAuth converts a garth session to a legacy authentication token
func GarthToLegacyAuth(session *garth.Session) (*Token, error) {
if session == nil {
return nil, fmt.Errorf("session cannot be nil")
}
return &Token{
OAuthToken: session.OAuth1Token,
OAuthSecret: session.OAuth1Secret,
AccessToken: session.OAuth2Token,
}, nil
}