Skip to content

Commit

Permalink
fix: use file persistence if encrycted fails due to importerror (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil authored Sep 6, 2024
1 parent bb704e4 commit 5697405
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions msal_bearer/BearerAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import msal
from msal_extensions import (
build_encrypted_persistence,
PersistedTokenCache,
FilePersistence,
PersistedTokenCache
)

_token_location = "token_cache.bin"
Expand Down Expand Up @@ -95,7 +96,11 @@ def get_app_with_cache(client_id, authority: str, token_location: str = ""):
# Uses default token location
pass

persistence = build_encrypted_persistence(get_token_location())
try:
persistence = build_encrypted_persistence(get_token_location())
except ImportError:
# Handle linux case of missing gi library
persistence = FilePersistence(get_token_location())

cache = PersistedTokenCache(persistence)
return msal.PublicClientApplication(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "msal-bearer"
version = "1.1.0"
version = "1.1.1"
description = "Python package to get auth token interactively for a public client application using msal and msal-extension for caching."
authors = ["Åsmund Våge Fannemel <asmf@equinor.com>"]
license = "MIT"
Expand Down

0 comments on commit 5697405

Please sign in to comment.