iaptoolkit 0.3.0a0__tar.gz → 0.3.0a2__tar.gz

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.
Files changed (20) hide show
  1. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/PKG-INFO +5 -1
  2. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/pyproject.toml +4 -1
  3. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/__init__.py +27 -5
  4. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/structs.py +1 -1
  5. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/LICENSE +0 -0
  6. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/README.md +0 -0
  7. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/constants.py +0 -0
  8. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/exceptions.py +0 -0
  9. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/headers.py +0 -0
  10. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/__init__.py +0 -0
  11. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/base.py +0 -0
  12. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oauth2/__init__.py +0 -0
  13. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oauth2/datastore_oauth2.py +0 -0
  14. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oauth2/gua.py +0 -0
  15. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oidc/__init__.py +0 -0
  16. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oidc/datastore_oidc.py +0 -0
  17. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/oidc/gsa.py +0 -0
  18. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/tokens/token_datastore.py +0 -0
  19. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/utils/__init__.py +0 -0
  20. {iaptoolkit-0.3.0a0 → iaptoolkit-0.3.0a2}/src/iaptoolkit/utils/urls.py +0 -0
@@ -1,10 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iaptoolkit
3
- Version: 0.3.0a0
3
+ Version: 0.3.0a2
4
4
  Summary: Library of common utils for interacting with Identity-Aware Proxies
5
+ Home-page: https://github.com/RAVoigt/iaptoolkit
6
+ License: MIT
5
7
  Author: Rob Voigt
6
8
  Author-email: code@ravoigt.com
7
9
  Requires-Python: >=3.11,<4.0
10
+ Classifier: License :: OSI Approved :: MIT License
8
11
  Classifier: Programming Language :: Python :: 3
9
12
  Classifier: Programming Language :: Python :: 3.11
10
13
  Classifier: Programming Language :: Python :: 3.12
@@ -13,6 +16,7 @@ Requires-Dist: kvcommon (>=0.1.4,<0.2.0)
13
16
  Requires-Dist: pytest (>=7.4.4,<8.0.0)
14
17
  Requires-Dist: requests (>=2.31.0,<3.0.0)
15
18
  Requires-Dist: toml (>=0.10.2,<0.11.0)
19
+ Project-URL: Repository, https://github.com/RAVoigt/iaptoolkit
16
20
  Description-Content-Type: text/markdown
17
21
 
18
22
  # IAP Toolkit
@@ -1,9 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "iaptoolkit"
3
- version = "0.3.0a"
3
+ version = "0.3.0a2"
4
4
  description = "Library of common utils for interacting with Identity-Aware Proxies"
5
5
  authors = ["Rob Voigt <code@ravoigt.com>"]
6
6
  readme = "README.md"
7
+ license = "MIT"
8
+ repository = "https://github.com/RAVoigt/iaptoolkit"
9
+ homepage = "https://github.com/RAVoigt/iaptoolkit"
7
10
 
8
11
  [build-system]
9
12
  requires = ["poetry-core>=1.0.0"]
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
+ import datetime
4
5
  import logging
5
6
 
6
7
  logging.getLogger(__name__).addHandler(logging.NullHandler())
@@ -18,6 +19,7 @@ from iaptoolkit.tokens.oauth2 import OAuth2
18
19
  from iaptoolkit.tokens.oidc import OIDC
19
20
  from iaptoolkit.tokens.structs import ResultAddTokenHeader
20
21
  from iaptoolkit.tokens.structs import TokenRefreshStruct
22
+ from iaptoolkit.tokens.structs import TokenStructOAuth2
21
23
  from iaptoolkit.utils.urls import is_url_safe_for_token
22
24
 
23
25
  LOG = get_logger("iaptk")
@@ -43,11 +45,11 @@ class IAPToolkit(ABC):
43
45
 
44
46
  @abstractmethod
45
47
  def get_token(
46
- self, refresh_token: str | None, bypass_cached: bool = False
48
+ self, refresh_token: str | None = None, bypass_cached: bool = False
47
49
  ) -> TokenRefreshStruct:
48
50
  raise NotImplementedError()
49
51
 
50
- def get_token_str(self, refresh_token: str | None, bypass_cached: bool = False) -> str:
52
+ def get_token_str(self, refresh_token: str | None = None, bypass_cached: bool = False) -> str:
51
53
  struct = self.get_token(refresh_token=refresh_token, bypass_cached=bypass_cached)
52
54
  return struct.id_token
53
55
 
@@ -127,13 +129,16 @@ class IAPToolkit_OIDC(IAPToolkit):
127
129
  """
128
130
  OIDC-only implementation of IAPToolkit
129
131
  """
132
+
130
133
  _interface: OIDC
131
134
 
132
135
  def __init__(self, google_iap_client_id: str) -> None:
133
136
  super().__init__(google_iap_client_id)
134
137
  self._interface = OIDC(iap_client_id=google_iap_client_id)
135
138
 
136
- def get_token(self, bypass_cached: bool = False) -> TokenRefreshStruct:
139
+ def get_token(
140
+ self, refresh_token: str | None = None, bypass_cached: bool = False
141
+ ) -> TokenRefreshStruct:
137
142
  try:
138
143
  return self._interface.get_token(
139
144
  iap_client_id=self._GOOGLE_IAP_CLIENT_ID, bypass_cached=bypass_cached
@@ -163,8 +168,25 @@ class IAPToolkit_OAuth2(IAPToolkit):
163
168
  self._GOOGLE_CLIENT_SECRET = google_client_secret
164
169
  self._interface = OAuth2(iap_client_id=google_iap_client_id, client_id=google_client_id)
165
170
 
166
- def get_refresh_token(self, bypass_cached: bool = False) -> t.Any:
167
- pass
171
+ def get_refresh_token(
172
+ self, auth_code: str, redirect_uri: str, bypass_cached: bool = False
173
+ ) -> t.Any:
174
+
175
+ # TODO: Cache
176
+ # TODO: Expiry
177
+ expired = True
178
+
179
+ if expired or bypass_cached:
180
+ refresh_token = self._interface.get_refresh_token_from_auth_code(
181
+ client_id=self._GOOGLE_CLIENT_ID,
182
+ client_secret=self._GOOGLE_CLIENT_SECRET,
183
+ auth_code=auth_code,
184
+ redirect_uri=redirect_uri,
185
+ )
186
+
187
+ # TODO: Expiry
188
+ # TODO: Move this when implementing cache
189
+ return TokenStructOAuth2(refresh_token=refresh_token, token_is_new=expired or bypass_cached)
168
190
 
169
191
  def get_token(self, refresh_token: str, bypass_cached: bool = False) -> TokenRefreshStruct:
170
192
  if not self._GOOGLE_CLIENT_ID or not self._GOOGLE_CLIENT_SECRET:
@@ -41,7 +41,7 @@ class TokenRefreshStruct:
41
41
 
42
42
 
43
43
  @dataclass(kw_only=True)
44
- class TokenStructOAuth2(TokenStruct):
44
+ class TokenStructOAuth2:
45
45
  refresh_token: str
46
46
  token_is_new: bool = False
47
47
 
File without changes
File without changes