Skip to content

Commit 9a621bd

Browse files
authored
Added a new auth_token property to AuthSession class (#350)
* add auth session property added tests fixed names remove formating noise remove formating from test * update packages * bump python version to 3.9 * adjust versions * fix plugin for poetry
1 parent 8ef4d50 commit 9a621bd

14 files changed

Lines changed: 1552 additions & 236 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
python-version: [ '3.8', '3.10' ]
14+
python-version: [ '3.9', '3.10' ]
1515
os: [ ubuntu-latest, macos-latest, windows-latest ]
1616
include:
1717
- os: ubuntu-latest

.github/workflows/cve-scanning-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python-version: "3.10"
2424
- uses: abatilo/actions-poetry@192395c0d10c082a7c62294ab5d9a9de40e48974
2525
with:
26-
poetry-version: "1.2.2"
26+
poetry-version: "2.0.0"
2727
- name: Install safety
2828
run: pip3 install safety
2929
- name: Build app

.github/workflows/push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
with:
2525
fetch-depth: 0
2626

27-
- name: Set up Python 3.8
27+
- name: Set up Python 3.9
2828
id: setup-python
2929
uses: actions/setup-python@v4
3030
with:
31-
python-version: 3.8
31+
python-version: 3.9
3232

3333
- name: Copy main branch into gh-pages
3434
run: |

.github/workflows/pylint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
- name: Checkout Code
1616
uses: actions/checkout@v4
1717

18-
- name: Set up Python 3.8
18+
- name: Set up Python 3.9
1919
id: setup-python
2020
uses: actions/setup-python@v4
2121
with:
22-
python-version: 3.8
22+
python-version: 3.9
2323

2424
- name: Get pip cache dir
2525
id: pip-cache

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- name: Set up Python 3.8
16+
- name: Set up Python 3.9
1717
uses: actions/setup-python@v4
1818
with:
19-
python-version: 3.8
19+
python-version: 3.9
2020

2121
- name: Install Poetry
2222
run: pip install poetry

.github/workflows/security.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
- name: Checkout Code
1616
uses: actions/checkout@v4
1717

18-
- name: Set up Python 3.8
18+
- name: Set up Python 3.9
1919
id: setup-python
2020
uses: actions/setup-python@v4
2121
with:
22-
python-version: 3.8
22+
python-version: 3.9
2323

2424
- name: Get pip cache dir
2525
id: pip-cache

examples/authentication/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ async def run():
1212
auth_session = bdk.bot_session()
1313
logging.info(await auth_session.key_manager_token)
1414
logging.info(await auth_session.session_token)
15+
logging.info(await auth_session.auth_token)
1516
logging.info("Obo example:")
1617
obo_auth_session = bdk.obo(username="username")
1718
logging.info(await obo_auth_session.session_token)

poetry.lock

Lines changed: 1433 additions & 216 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ packages = [
1212
]
1313

1414
[tool.poetry.dependencies]
15-
python = "^3.8"
15+
python = "^3.9"
1616
nulltype = "^2.3.1"
1717
python-dateutil = "^2.8.2"
1818
urllib3 = "^1.26.19"
1919
aiohttp = "^3.10.2"
2020
pyyaml = "^6.0"
21-
PyJWT = "^2.3.0"
21+
PyJWT = "^2.10.0"
2222
cryptography = "^43.0.1"
2323
tenacity = "^8.0.1"
2424
defusedxml = "^0.7.1"
@@ -37,6 +37,9 @@ safety = "^2.2.0"
3737
liccheck = "^0.6.2"
3838
coverage = {version = "^6.0b1", extras = ["toml"]}
3939

40+
[tool.poetry.requires-plugins]
41+
poetry-plugin-export = ">=1.8"
42+
4043
[build-system]
4144
requires = ["poetry-core>=1.0.0"]
4245
build-backend = "poetry.core.masonry.api"

symphony/bdk/core/auth/auth_session.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Module containing session handle classes.
22
33
"""
4+
from datetime import datetime, timezone
45
import logging
56

67
from symphony.bdk.core.auth.exception import AuthInitializationError
78

89
logger = logging.getLogger(__name__)
910

11+
EXPIRATION_SAFETY_BUFFER_SECONDS = 5
12+
1013

1114
class AuthSession:
1215
"""RSA Authentication session handle to get session and key manager tokens from.
@@ -21,7 +24,9 @@ def __init__(self, authenticator):
2124
"""
2225
self._session_token = None
2326
self._key_manager_token = None
27+
self._auth_token = None
2428
self._authenticator = authenticator
29+
self._expire_at = -1
2530

2631
async def refresh(self):
2732
"""Trigger re-authentication to refresh the tokens.
@@ -40,6 +45,26 @@ async def session_token(self):
4045
self._session_token = await self._authenticator.retrieve_session_token()
4146
return self._session_token
4247

48+
@property
49+
async def auth_token(self):
50+
"""Auth token request calls the same endpoint that session token.
51+
Therefore, session token is updated unintentionally,
52+
since there's no explicit way to update authorization token exclusively
53+
: return: (str) authorization_token like Bearer eyJh...
54+
"""
55+
56+
if (
57+
self._auth_token
58+
and self._expire_at
59+
> datetime.now(timezone.utc).timestamp() + EXPIRATION_SAFETY_BUFFER_SECONDS
60+
):
61+
return self._auth_token
62+
token, expire_at = await self._authenticator.retrieve_session_token_object()
63+
self._expire_at = expire_at
64+
self._auth_token = token.authorization_token
65+
self._session_token = token.token
66+
return self._auth_token
67+
4368
@property
4469
async def key_manager_token(self):
4570
"""

0 commit comments

Comments
 (0)