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

Add-instace-support #157

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ tsd_api_client.egg-info/
build/
dist/
__pycache__
.DS_Store
.DS_Store
.vscode/
383 changes: 262 additions & 121 deletions poetry.lock

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion tsdapiclient/authapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

"""Module for the TSD Auth API."""

import json
from uuid import UUID
import requests
import time

Expand Down Expand Up @@ -45,6 +45,36 @@ def get_jwt_basic_auth(
msg = resp.text
raise AuthnError(msg)


def get_jwt_instance_auth(
env: str,
pnum: str,
api_key: str,
link_id: UUID,
secret_challenge: str|None = None,
token_type: str = "import",
) -> tuple:
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}
url = f'{auth_api_url(env, pnum, "instances")}?type={token_type}'
try:
debug_step(f"POST {url}")
request_body = {"id": str(link_id)}
if secret_challenge:
request_body["secret_challenge"] = secret_challenge
resp = requests.post(url, headers=headers, data=json.dumps(request_body))
except Exception as e:
raise AuthnError from e
if resp.status_code in [200, 201]:
data = json.loads(resp.text)
return data.get("token"), data.get("refresh_token")
else:
if resp.status_code == 403:
msg = f"Instance auth not authorized from current IP address, contact USIT at {HELP_URL}"
else:
msg = resp.text
raise AuthnError(msg)


@handle_request_errors
def get_jwt_two_factor_auth(
env: str,
Expand Down
Loading