Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for return_on_mfa code #92

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ garth.login(email, password, prompt_mfa=lambda: input("Enter MFA code: "))
For advanced use cases (like async handling), MFA can be handled separately:

```python
result = garth.login(email, password, return_on_mfa=True)
if isinstance(result, dict): # MFA is required
result1, result2 = garth.login(email, password, return_on_mfa=True)
if result1 == "needs_mfa": # MFA is required
mfa_code = "123456" # Get this from your custom MFA flow
oauth1, oauth2 = garth.resume_login(result['client_state'], mfa_code)
oauth1, oauth2 = garth.resume_login(result2, mfa_code)
```

### Configure
Expand Down
13 changes: 11 additions & 2 deletions garth/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,19 @@ def put(self, *args, **kwargs) -> Response:
return self.request("PUT", *args, **kwargs)

def login(self, *args, **kwargs):
self.oauth1_token, self.oauth2_token = sso.login(
oauth1, oauth2 = sso.login(
*args, **kwargs, client=self
)

self.oauth1_token = oauth1
self.oauth2_token = oauth2
return oauth1, oauth2

def resume_login(self, *args, **kwargs):
self.oauth1_token, self.oauth2_token = sso.resume_login(
*args, **kwargs, # client=self
)
return self.oauth1_token, self.oauth2_token
cyberjunky marked this conversation as resolved.
Show resolved Hide resolved

def refresh_oauth2(self):
assert self.oauth1_token, "OAuth1 token is required for OAuth2 refresh"
# There is a way to perform a refresh of an OAuth2 token, but it
Expand Down
11 changes: 4 additions & 7 deletions garth/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,10 @@ def login(
# Handle MFA
if "MFA" in title:
if return_on_mfa or prompt_mfa is None:
return {
"needs_mfa": True,
"client_state": {
"csrf_token": csrf_token,
"signin_params": SIGNIN_PARAMS,
"client": client,
},
return "needs_mfa", {
"csrf_token": csrf_token,
"signin_params": SIGNIN_PARAMS,
"client": client,
cyberjunky marked this conversation as resolved.
Show resolved Hide resolved
}

handle_mfa(client, SIGNIN_PARAMS, prompt_mfa)
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.5.2"
__version__ = "0.5.3"
Loading