Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ bb2_venv/
# BB2 ignores
.bluebutton-config.json
.bluebutton-config.yaml

# Snyk Security Extension - AI Rules (auto-generated)
.github/instructions/snyk_rules.instructions.md
47 changes: 47 additions & 0 deletions README-sdk-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,50 @@ To do this, edit the following line in the `./cms_bluebutton/version.py` file wi
__version__ = "1.0.0",
```

### Testing Locally

The current method for seeing the SDK in action is fairly complex, as it requires also setting up the Python sample client (https://github.com/CMSgov/bluebutton-sample-client-python-react/tree/main). These both, of course, depend upon the web-server repo for most of their logic. It is possible that in order to fully understand an issue that arises within the SDK or the sample client, a developer would have to track changes across 3 separate projects. There should be some future work to simplify this process as it is very manual and laborious.

The steps listed here are listed elsewhere in the documentation but for the sake of convenience, they are partially repeated here
and written together so that a developer should be able to follow this step by step.

The overall goals are to:

- Build a local version of the SDK
- Run a local version of sample client that consumes a local version of the SDK

### Building a local version of the SDK

Run the following commands in the base of this SDK repository. The commands suppose that you have the Python sample client cloned in the same folder as this SDK repo. Do not be in a virtualenv while running these commands.

```
rm -rf build/
python -m build --wheel --o ../bluebutton-sample-client-python-react/server
```

The --o (or outdir) command should effectively 'copy paste' the built version of the .whl file into where it would be needed for the sample client. If you do not want it in the sample client, omit the --o and file path.

### Run a local version of sample client that consumes a local version of the SDK

Ensure that in bluebutton-sample-client-python-react/server/Dockerfile, uncomment the following line. Replace the version number (1.0.4 in the example) of the .whl file with what has been generated from the previous build command.

```
RUN pip install cms_bluebutton_sdk-1.0.4-py3-none-any.whl
```

In bluebutton-sample-client-python-react/server/Pipfile, add this line:

```
cms-bluebutton-sdk = {file = "./cms_bluebutton_sdk-1.0.4-py3-none-any.whl"}
```

In the base repository of bluebutton-sample-client-python-react, run the following commands. Ensure that you have no currently running containers or images of the sample client.

```
cd server
unzip -l cms_bluebutton_sdk-1.0.4-py3-none-any.whl
pip install cms_bluebutton_sdk-1.0.4-py3-none-any.whl
docker compose up
```

Each time a change is made in the SDK, you must repeat all of the previous steps of building and re-running a local sample client. You must also ensure that the containers and images are removed each time.
2 changes: 1 addition & 1 deletion bluebutton-sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"client_id": "<your BB2 client_id here>",
"client_secret": "<your BB2 client_secret here.>",
"callback_url": "https://www.fake.com/your/callback/here",
"version": 2
"version": 3
}
6 changes: 3 additions & 3 deletions cms_bluebutton/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def generate_pkce_data() -> dict:
code_challenge = base64.urlsafe_b64encode(
hashlib.sha256(verifier.encode("ASCII")).digest()
)
return {"code_challenge": code_challenge.decode("utf-8"), "verifier": verifier}
return {"code_challenge": code_challenge.decode("utf-8"), "code_challenge_method": "S256", "verifier": verifier}


def generate_random_state(num) -> str:
Expand All @@ -116,7 +116,6 @@ def get_access_token_from_code(bb, auth_data, callback_code) -> dict:
"grant_type": "authorization_code",
"redirect_uri": bb.callback_url,
"code_verifier": auth_data["verifier"],
"code_challenge": auth_data["code_challenge"],
}

token_response = _do_post(data, bb, None)
Expand Down Expand Up @@ -146,10 +145,11 @@ def _do_post(data, bb, auth):
mp_encoder = MultipartEncoder(data)
headers = SDK_HEADERS
headers["content-type"] = mp_encoder.content_type

return requests.post(
url=bb.auth_token_url,
data=mp_encoder,
headers=headers
headers=headers,
) if not auth else requests.post(
url=bb.auth_token_url,
data=mp_encoder,
Expand Down
1 change: 0 additions & 1 deletion cms_bluebutton/cms_bluebutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
ROOT_DIR = os.path.abspath(os.curdir) + "/"
DEFAULT_CONFIG_FILE_LOCATION = ROOT_DIR + "./.bluebutton-config.json"


class BlueButton:

def __init__(self, config=DEFAULT_CONFIG_FILE_LOCATION):
Expand Down