Skip to content

Commit

Permalink
Set domain on OAuth1 token (#25)
Browse files Browse the repository at this point in the history
* Add domain to OAuth1 token. Closes #24

* make sure mfa_expiration_timestamp is in the future

* bump version
  • Loading branch information
matin committed Oct 5, 2023
1 parent 515933f commit 43196b5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions garth/auth_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OAuth1Token:
oauth_token_secret: str
mfa_token: Optional[str] = None
mfa_expiration_timestamp: Optional[datetime] = None
domain: Optional[str] = None


@dataclass
Expand Down
5 changes: 4 additions & 1 deletion garth/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ def load(self, dir_path: str):
oauth1 = OAuth1Token(**json.load(f))
with open(os.path.join(dir_path, "oauth2_token.json")) as f:
oauth2 = OAuth2Token(**json.load(f))
self.configure(oauth1_token=oauth1, oauth2_token=oauth2)
self.configure(
oauth1_token=oauth1, oauth2_token=oauth2, domain=oauth1.domain
)

def loads(self, s: str):
oauth1, oauth2 = json.loads(base64.b64decode(s))
self.configure(
oauth1_token=OAuth1Token(**oauth1),
oauth2_token=OAuth2Token(**oauth2),
domain=oauth1.get("domain"),
)


Expand Down
2 changes: 1 addition & 1 deletion garth/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_oauth1_token(ticket: str, client: "http.Client") -> OAuth1Token:
resp.raise_for_status()
parsed = parse_qs(resp.text)
token = {k: v[0] for k, v in parsed.items()}
return OAuth1Token(**token) # type: ignore
return OAuth1Token(domain=client.domain, **token) # type: ignore


def exchange(oauth1: OAuth1Token, client: "http.Client") -> OAuth2Token:
Expand Down
2 changes: 1 addition & 1 deletion garth/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.37"
__version__ = "0.4.38"
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def oauth1_token_dict() -> dict:
oauth_token="7fdff19aa9d64dda83e9d7858473aed1",
oauth_token_secret="49919d7c4c8241ac93fb4345886fbcea",
mfa_token="ab316f8640f3491f999f3298f3d6f1bb",
mfa_expiration_timestamp="2023-08-02 05:56:10.000",
mfa_expiration_timestamp="2024-08-02 05:56:10.000",
domain="garmin.com",
)


Expand Down

0 comments on commit 43196b5

Please sign in to comment.