Skip to content

Commit 14d4195

Browse files
committed
not currently working v3 changes
1 parent 7fca77c commit 14d4195

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,6 @@ bb2_venv/
169169
# BB2 ignores
170170
.bluebutton-config.json
171171
.bluebutton-config.yaml
172+
173+
# Snyk Security Extension - AI Rules (auto-generated)
174+
.github/instructions/snyk_rules.instructions.md

bluebutton-sample-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"environment": "SANDBOX",
3-
"client_id": "<your BB2 client_id here>",
4-
"client_secret": "<your BB2 client_secret here.>",
5-
"callback_url": "https://www.fake.com/your/callback/here",
6-
"version": 2
3+
"client_id": "Lb0hAgLi7rtyZvJMucZDDj0i0IKQWqiQrWSVZCZ7",
4+
"client_secret": "JsLVxfaugDqUgowsXNXgoHRroWakt9QFFzYVhaK7Db0aN6DegK9Kn4a56awCOLWkxGiq6dRqgSLX4jAzBFxZNk3XJFERUTHbH1TMvpEsNtP76nrF9ZdkyB3PZT9GFaxr",
5+
"callback_url": "http://localhost:3001/api/bluebutton/callback/",
6+
"version": 3
77
}

cms_bluebutton/auth.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def generate_pkce_data() -> dict:
9595
code_challenge = base64.urlsafe_b64encode(
9696
hashlib.sha256(verifier.encode("ASCII")).digest()
9797
)
98-
return {"code_challenge": code_challenge.decode("utf-8"), "verifier": verifier}
98+
return {"code_challenge": code_challenge.decode("utf-8"), "code_challenge_method": "S256", "verifier": verifier}
9999

100100

101101
def generate_random_state(num) -> str:
@@ -108,7 +108,7 @@ def generate_auth_data() -> dict:
108108
return auth_data
109109

110110

111-
def get_access_token_from_code(bb, auth_data, callback_code) -> dict:
111+
def get_access_token_from_code(bb, auth_data, callback_code, callback_state) -> dict:
112112
data = {
113113
"client_id": bb.client_id,
114114
"client_secret": bb.client_secret,
@@ -117,10 +117,20 @@ def get_access_token_from_code(bb, auth_data, callback_code) -> dict:
117117
"redirect_uri": bb.callback_url,
118118
"code_verifier": auth_data["verifier"],
119119
"code_challenge": auth_data["code_challenge"],
120+
"code_challenge_method": "S256",
121+
"state": callback_state,
120122
}
121123

122124
token_response = _do_post(data, bb, None)
123-
token_response.raise_for_status()
125+
try:
126+
token_response.raise_for_status()
127+
except requests.exceptions.HTTPError as e:
128+
print(f'Error obtaining access token: {e}')
129+
print(f'Response content: {token_response.text}')
130+
print(f'Request data: {data}')
131+
print(f'Request headers: {SDK_HEADERS}')
132+
print(f'Request URL: {bb.auth_token_url}')
133+
raise
124134
token_dict = token_response.json()
125135
token_dict["expires_at"] = datetime.datetime.now(
126136
datetime.timezone.utc
@@ -139,17 +149,22 @@ def get_authorization_token(bb, auth_data, callback_code, callback_state):
139149
if callback_state != auth_data["state"]:
140150
raise ValueError("Provided callback state does not match.")
141151

142-
return AuthorizationToken(get_access_token_from_code(bb, auth_data, callback_code))
152+
return AuthorizationToken(get_access_token_from_code(bb, auth_data, callback_code, callback_state))
143153

144154

145155
def _do_post(data, bb, auth):
146156
mp_encoder = MultipartEncoder(data)
147157
headers = SDK_HEADERS
148158
headers["content-type"] = mp_encoder.content_type
159+
print(f'headers: {headers}')
160+
print(f'url: {bb.auth_token_url}')
161+
print(f'data: {data}')
162+
print(f'auth: {auth}')
163+
149164
return requests.post(
150165
url=bb.auth_token_url,
151166
data=mp_encoder,
152-
headers=headers
167+
headers=headers,
153168
) if not auth else requests.post(
154169
url=bb.auth_token_url,
155170
data=mp_encoder,

cms_bluebutton/cms_bluebutton.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919

2020
ROOT_DIR = os.path.abspath(os.curdir) + "/"
21+
print("ROOT_DIR:", ROOT_DIR)
2122
DEFAULT_CONFIG_FILE_LOCATION = ROOT_DIR + "./.bluebutton-config.json"
23+
print("DEFAULT_CONFIG_FILE_LOCATION:", DEFAULT_CONFIG_FILE_LOCATION)
2224

2325

2426
class BlueButton:
@@ -154,4 +156,8 @@ def generate_authorize_url(self, auth_data):
154156
return generate_authorize_url(self, auth_data)
155157

156158
def get_authorization_token(self, auth_data, callback_code, callback_state):
159+
print("Getting authorization token...")
160+
print("Auth Data:", auth_data)
161+
print("Callback Code:", callback_code)
162+
print("Callback State:", callback_state)
157163
return get_authorization_token(self, auth_data, callback_code, callback_state)

0 commit comments

Comments
 (0)