Skip to content

Commit e607e89

Browse files
committed
replace post functions with get
1 parent cf33026 commit e607e89

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

microSALT/utils/pubmlst/get_credentials.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@ def validate_credentials(client_id, client_secret):
2121
def get_new_access_token(
2222
client_id, client_secret, db: str, base_api: str, base_web: str
2323
) -> tuple[str, str]:
24-
"""Obtain a new access token and secret."""
25-
# Step 1: fetch request token
24+
"""Obtain a new access token and secret.
25+
26+
BIGSdb OAuth endpoints require GET (not POST), so we use oauth.get()
27+
directly rather than requests-oauthlib's fetch_request_token/fetch_access_token
28+
helpers, which both default to POST.
29+
"""
30+
# Step 1: GET request token
2631
oauth = OAuth1Session(client_id, client_secret=client_secret, callback_uri="oob")
27-
response = oauth.fetch_request_token(f"{base_api}/db/{db}/oauth/get_request_token")
28-
if not response:
29-
print("Error obtaining request token.")
32+
response = oauth.get(f"{base_api}/db/{db}/oauth/get_request_token")
33+
if not response.ok:
34+
print(f"Error obtaining request token: {response.text}")
3035
sys.exit(1)
31-
request_token = response["oauth_token"]
32-
request_secret = response["oauth_token_secret"]
36+
token_data = response.json()
37+
request_token = token_data["oauth_token"]
38+
request_secret = token_data["oauth_token_secret"]
3339

3440
print(
3541
"Please log in using your user account at "
@@ -38,18 +44,19 @@ def get_new_access_token(
3844
)
3945
verifier = input("Please enter verification code: ")
4046

41-
# Step 2: exchange for access token
47+
# Step 2: GET access token
4248
oauth = OAuth1Session(
4349
client_id,
4450
client_secret=client_secret,
4551
resource_owner_key=request_token,
4652
resource_owner_secret=request_secret,
4753
verifier=verifier,
4854
)
49-
access_data = oauth.fetch_access_token(f"{base_api}/db/{db}/oauth/get_access_token")
50-
if not access_data:
51-
print("Error obtaining access token.")
55+
response = oauth.get(f"{base_api}/db/{db}/oauth/get_access_token")
56+
if not response.ok:
57+
print(f"Error obtaining access token: {response.text}")
5258
sys.exit(1)
59+
access_data = response.json()
5360
return access_data["oauth_token"], access_data["oauth_token_secret"]
5461

5562

0 commit comments

Comments
 (0)