Skip to content

Commit

Permalink
Merge pull request #20 from praekeltfoundation/configurable_jwt
Browse files Browse the repository at this point in the history
Change to longer-lived JWT's.
  • Loading branch information
Schalk1e authored Nov 20, 2024
2 parents 7b3f09c + 12a5564 commit 72be39d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ TURN_API_BASE_URL="<url>"
For the turn_bq API: (New Addition)

```
TURN_BQ_API_USER="<user>"
TURN_BQ_API_PASS="<password>"
TURN_BQ_API_KEY="<secret>"
TURN_BQ_API_BASE_URL="<url>"
```
Expand Down
28 changes: 2 additions & 26 deletions rdw_ingestion_tools/api/turn_bq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@

from .. import config_from_env

USER = config_from_env("TURN_BQ_API_USER")
PASS = config_from_env("TURN_BQ_API_PASS")
API_KEY = config_from_env("TURN_BQ_API_KEY")
BASE_URL = config_from_env("TURN_BQ_API_BASE_URL")

token_request_headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}

token_request_data = {
"grant_type": "password",
"username": f"{USER}",
"password": f"{PASS}",
"client_id": "",
"client_secret": "",
}

token_response = Client().post(
url=f"{BASE_URL}/token",
headers=token_request_headers,
data=token_request_data,
)

token_response.raise_for_status()

access_token = token_response.json()["access_token"]

session_headers = {
"Authorization": f"Bearer {access_token}",
"Authorization": f"Bearer {API_KEY}",
"Accept": "application/vnd.v1+json",
"Content-Type": "application/json",
}
Expand Down

0 comments on commit 72be39d

Please sign in to comment.