pypomes-iam 0.2.8__tar.gz → 0.2.9__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.
Potentially problematic release.
This version of pypomes-iam might be problematic. Click here for more details.
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/PKG-INFO +1 -1
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/pyproject.toml +1 -1
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/iam_pomes.py +39 -2
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/.gitignore +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/LICENSE +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/README.md +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/__init__.py +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/iam_common.py +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/jusbr_pomes.py +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/keycloak_pomes.py +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/provider_pomes.py +0 -0
- {pypomes_iam-0.2.8 → pypomes_iam-0.2.9}/src/pypomes_iam/token_pomes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_iam
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: A collection of Python pomes, penyeach (IAM modules)
|
|
5
5
|
Project-URL: Homepage, https://github.com/TheWiseCoder/PyPomes-IAM
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/TheWiseCoder/PyPomes-IAM/issues
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import requests
|
|
1
3
|
from flask import Response, request, jsonify
|
|
2
4
|
from logging import Logger
|
|
3
5
|
from typing import Any
|
|
@@ -103,14 +105,49 @@ def service_callback() -> Response:
|
|
|
103
105
|
args=request.args,
|
|
104
106
|
errors=errors,
|
|
105
107
|
logger=logger)
|
|
108
|
+
# exchange the token
|
|
109
|
+
if request.endpoint.startswith("jusbr-"):
|
|
110
|
+
keycloak_registry: dict[str, Any] = __get_iam_registry(endpoint="keycloak-token")
|
|
111
|
+
payload: dict[str, str] = {
|
|
112
|
+
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
113
|
+
"subject_token": token_data[1],
|
|
114
|
+
"subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
|
|
115
|
+
"client_id": keycloak_registry["client-id"],
|
|
116
|
+
"client_secret": keycloak_registry["client-secret"],
|
|
117
|
+
"requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
|
|
118
|
+
"audience": token_data[0]
|
|
119
|
+
}
|
|
120
|
+
exchange_url = f"{keycloak_registry['base-url']}/protocol/openid-connect/token"
|
|
121
|
+
if logger:
|
|
122
|
+
logger.debug(msg=f"POST '{exchange_url}', data {json.dumps(obj=payload,
|
|
123
|
+
ensure_ascii=False)}")
|
|
124
|
+
headers: dict[str, str] = {
|
|
125
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
126
|
+
}
|
|
127
|
+
response: requests.Response = requests.post(url=exchange_url,
|
|
128
|
+
data=payload,
|
|
129
|
+
headers=headers)
|
|
130
|
+
if response.status_code == 200:
|
|
131
|
+
# request succeeded
|
|
132
|
+
if logger:
|
|
133
|
+
logger.debug(msg=f"POST success, status {response.status_code}")
|
|
134
|
+
reply: dict[str, Any] = response.json()
|
|
135
|
+
token_data = (token_data[0], reply.get("access_token"))
|
|
136
|
+
else:
|
|
137
|
+
# request resulted in error
|
|
138
|
+
err_msg = f"POST failure, status {response.status_code}, reason '{response.reason}'"
|
|
139
|
+
if hasattr(response, "content") and response.content:
|
|
140
|
+
err_msg += f", content '{response.content}'"
|
|
141
|
+
errors.append(err_msg)
|
|
142
|
+
|
|
106
143
|
result: Response
|
|
107
144
|
if errors:
|
|
108
145
|
result = jsonify({"errors": "; ".join(errors)})
|
|
109
146
|
result.status_code = 400
|
|
110
147
|
else:
|
|
111
148
|
result = jsonify({
|
|
112
|
-
"
|
|
113
|
-
"
|
|
149
|
+
"user-id": token_data[0],
|
|
150
|
+
"access-token": token_data[1]})
|
|
114
151
|
|
|
115
152
|
# log the response
|
|
116
153
|
if logger:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|