mirror of
https://github.com/sstent/go-garminconnect.git
synced 2026-02-08 07:21:47 +00:00
with garth
This commit is contained in:
33
internal/auth/compat.go
Normal file
33
internal/auth/compat.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user