From 86278c360fd3442aff7f799c6f5968cbe24463bf Mon Sep 17 00:00:00 2001 From: pstruebi Date: Mon, 24 Jun 2024 21:51:14 +0200 Subject: [PATCH] Fix token caching --- Dockerfile | 5 +++-- propedal-planner/calendar_interface.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index de4f20f..f864799 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/propedal-planner/calendar_interface.py b/propedal-planner/calendar_interface.py index f157ff1..8353ff7 100644 --- a/propedal-planner/calendar_interface.py +++ b/propedal-planner/calendar_interface.py @@ -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.")