Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify user name to use #5

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions msal_bearer/BearerAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)

_token_location = "token_cache.bin"
_username = ""


def set_token_location(location: str):
Expand Down Expand Up @@ -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.

Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <asmf@equinor.com>",
]
authors = ["Åsmund Våge Fannemel <asmf@equinor.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/Equinor/msal-bearer"
Expand All @@ -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"

Expand Down