Fix token caching

This commit is contained in:
2024-06-24 21:51:14 +02:00
parent be1aa99ada
commit 86278c360f
2 changed files with 6 additions and 4 deletions

View File

@@ -7,8 +7,9 @@ WORKDIR /app
# Copy the current directory contents into the container at /app
COPY ./propedal-planner /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Install any needed packages specified in requirements.txt -use cache
RUN --mount=type=cache,target=/root/.cache \
pip install -r requirements.txt
# Make port available to the world outside this container
EXPOSE 8001

View File

@@ -30,16 +30,17 @@ app = msal.ConfidentialClientApplication(
# You can learn how to use SerializableTokenCache from
# https:#msal-python.readthedocs.io/en/latest/#msal.SerializableTokenCache
)
accounts = app.get_accounts(username=None)
def get_access_token():
global app, token
global app, token, accounts
# The pattern to acquire a token looks like this.
# Firstly, looks up a token from cache
# Since we are looking for token for the current app, NOT for an end user,
# notice we give account parameter as None.
token = app.acquire_token_silent(MsalConfig.SCOPE, account=None)
token = app.acquire_token_silent(MsalConfig.SCOPE, account=accounts[0])
if token is None:
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")