From 07e583fa4f6822ba99c1e5d2f2d8c174865e90f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:26:49 +0200 Subject: [PATCH] feat: allow to specify user name to use --- msal_bearer/BearerAuth.py | 23 +++++++++++++++++++++++ pyproject.toml | 7 ++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/msal_bearer/BearerAuth.py b/msal_bearer/BearerAuth.py index a8155f7..d52f653 100644 --- a/msal_bearer/BearerAuth.py +++ b/msal_bearer/BearerAuth.py @@ -8,6 +8,7 @@ ) _token_location = "token_cache.bin" +_username = "" def set_token_location(location: str): @@ -40,6 +41,28 @@ def get_token_location() -> str: return _token_location +def set_user_name(username: str): + """Set user name. + + Args: + username (str): User name to use for user_impersonation + """ + global _username + _username = username + + +def get_user_name() -> Union[str, None]: + """Get user name if set using set_user_name or return result from get_login_name() + + Returns: + Union[str, None]: User name + """ + if not _username: + return get_login_name() + + return _username + + def get_login_name() -> Union[str, None]: """Get login name of current user. diff --git a/pyproject.toml b/pyproject.toml index bb0f167..50c5890 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,8 @@ [tool.poetry] name = "msal-bearer" -version = "1.0.0" +version = "1.1.0" 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 ", -] +authors = ["Åsmund Våge Fannemel "] license = "MIT" readme = "README.md" repository = "https://github.com/Equinor/msal-bearer" @@ -16,7 +14,6 @@ msal = "^1.28.0" msal-extensions = "^1.1.0" cryptography = "^42.0.6" - [tool.poetry.group.dev.dependencies] black = "^24.4.2"