aiohttp-msal 1.0.2__py3-none-any.whl → 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,12 +34,7 @@ HTTP_DELETE = "delete"
34
34
  HTTP_ALLOWED = [HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE]
35
35
 
36
36
  DEFAULT_SCOPES = ["User.Read", "User.Read.All"]
37
-
38
-
39
- # These keys will be used on the aiohttp session
40
- TOKEN_CACHE = "token_cache"
41
37
  FLOW_CACHE = "flow_cache"
42
- USER_EMAIL = "mail"
43
38
 
44
39
 
45
40
  @attrs.define()
@@ -59,37 +54,39 @@ class AsyncMSAL:
59
54
  """Called if the token cache changes. Optional.
60
55
  Not required when the session parameter is an aiohttp_session.Session.
61
56
  """
62
- app: ConfidentialClientApplication = attrs.field(init=False)
63
-
64
- app_kwargs: ClassVar[dict[str, Any] | None] = None
57
+ app_kwargs: dict[str, Any] | None = None
65
58
  """ConfidentialClientApplication kwargs."""
66
59
  client_session: ClassVar[ClientSession | None] = None
67
60
 
68
- def __attrs_post_init__(self) -> None:
69
- """Init."""
70
- kwargs = dict(self.app_kwargs) if self.app_kwargs else {}
71
- for key, val in {
61
+ token_cache_key: str = "token_cache"
62
+ user_email_key: str = "mail"
63
+
64
+ @cached_property
65
+ def app(self) -> ConfidentialClientApplication:
66
+ """Get the app."""
67
+ kwargs = {
72
68
  "client_id": ENV.SP_APP_ID,
73
69
  "client_credential": ENV.SP_APP_PW,
74
70
  "authority": ENV.SP_AUTHORITY,
75
71
  "validate_authority": False,
76
72
  "token_cache": self.token_cache,
77
- }.items():
78
- kwargs.setdefault(key, val)
79
- self.app = ConfidentialClientApplication(**kwargs)
73
+ }
74
+ if self.app_kwargs:
75
+ kwargs.update(self.app_kwargs)
76
+ return ConfidentialClientApplication(**kwargs)
80
77
 
81
78
  @cached_property
82
79
  def token_cache(self) -> SerializableTokenCache:
83
80
  """Get the token_cache."""
84
81
  res = SerializableTokenCache()
85
- if self.session and self.session.get(TOKEN_CACHE):
86
- res.deserialize(self.session[TOKEN_CACHE])
82
+ if tc := self.session.get(self.token_cache_key):
83
+ res.deserialize(tc)
87
84
  return res
88
85
 
89
86
  def save_token_cache(self) -> None:
90
87
  """Save the token cache if it changed."""
91
88
  if self.token_cache.has_state_changed:
92
- self.session[TOKEN_CACHE] = self.token_cache.serialize()
89
+ self.session[self.token_cache_key] = self.token_cache.serialize()
93
90
  if self.save_callback:
94
91
  self.save_callback(self.session)
95
92
 
@@ -101,8 +98,8 @@ class AsyncMSAL:
101
98
  **kwargs: Any,
102
99
  ) -> str:
103
100
  """First step - Start the flow."""
104
- self.session[TOKEN_CACHE] = None
105
- self.session[USER_EMAIL] = None
101
+ self.session.pop(self.token_cache_key, None)
102
+ self.session.pop(self.user_email_key, None)
106
103
  self.session[FLOW_CACHE] = res = self.app.initiate_auth_code_flow(
107
104
  scopes or DEFAULT_SCOPES,
108
105
  redirect_uri=redirect_uri,
@@ -131,7 +128,7 @@ class AsyncMSAL:
131
128
  raise web.HTTPBadRequest(text=f"Expected id_token_claims in {result}")
132
129
  self.save_token_cache()
133
130
  if tok := result.get("id_token_claims"):
134
- self.session[USER_EMAIL] = tok.get("preferred_username")
131
+ self.session[self.user_email_key] = tok.get("preferred_username")
135
132
 
136
133
  async def async_acquire_token_by_auth_code_flow(self, auth_response: Any) -> None:
137
134
  """Second step - Acquire token, async version."""
@@ -203,7 +200,7 @@ class AsyncMSAL:
203
200
  @property
204
201
  def mail(self) -> str:
205
202
  """User email."""
206
- return self.session.get(USER_EMAIL, "")
203
+ return self.session.get(self.user_email_key, "")
207
204
 
208
205
  @property
209
206
  def manager_mail(self) -> str:
@@ -223,4 +220,4 @@ class AsyncMSAL:
223
220
  @property
224
221
  def authenticated(self) -> bool:
225
222
  """If the user is logged in."""
226
- return bool(self.session.get("mail"))
223
+ return bool(self.session.get(self.user_email_key))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aiohttp-msal
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Helper Library to use the Microsoft Authentication Library (MSAL) with aiohttp
5
5
  Keywords: aiohttp,asyncio,msal,oauth
6
6
  Author: Johann Kellerman
@@ -1,11 +1,11 @@
1
1
  aiohttp_msal/__init__.py,sha256=hnyifyJykI7NMvM93KrHIsTlrrfCVUrpKdbRKL6Gubw,4027
2
- aiohttp_msal/msal_async.py,sha256=JUtyTro57rLiHQYqgYq8LFv3keznyhISP1emgN3y31E,8232
2
+ aiohttp_msal/msal_async.py,sha256=urQvaMTi0mJnCboCsj8A9F9VpWcjPOYaechpZ5XrnbY,8153
3
3
  aiohttp_msal/redis_tools.py,sha256=6kCw0_zDQcvIcsJaPfG-zHUvT3vzkrNySNTV5y1tckE,6539
4
4
  aiohttp_msal/routes.py,sha256=WyLBuoPMkkG6Cx4gFUu_ER71FyJbeXKhOQRQu5ALG2M,8138
5
5
  aiohttp_msal/settings.py,sha256=sArlq9vBDMsikLf9sTRw-UXE2_QRK_G-kzmtHvZcbwA,1559
6
6
  aiohttp_msal/settings_base.py,sha256=WBI7HS780i9zKWUy1ZnztDbRsfoDMVr3K-otHZOhNCc,3026
7
7
  aiohttp_msal/user_info.py,sha256=lxjFxjm16rvC-0LS81y7SG5pCOa5Zl0s62uxi97yu_k,1171
8
8
  aiohttp_msal/utils.py,sha256=SgGpE1eFdVh48FaKvtbnQqJKTReXa9OPBKiYGY7SYq8,1303
9
- aiohttp_msal-1.0.2.dist-info/WHEEL,sha256=4n27za1eEkOnA7dNjN6C5-O2rUiw6iapszm14Uj-Qmk,79
10
- aiohttp_msal-1.0.2.dist-info/METADATA,sha256=b9HRcY4HaOKhXVhBQIuYK-h0Cia9g922FjOdTyOuPpw,4514
11
- aiohttp_msal-1.0.2.dist-info/RECORD,,
9
+ aiohttp_msal-1.0.3.dist-info/WHEEL,sha256=4n27za1eEkOnA7dNjN6C5-O2rUiw6iapszm14Uj-Qmk,79
10
+ aiohttp_msal-1.0.3.dist-info/METADATA,sha256=raujaCawOODO6HYM79crhTECU28f_IjlkzIPmR8ck48,4514
11
+ aiohttp_msal-1.0.3.dist-info/RECORD,,