Skip to content

Fix/add device key to auth params if set#306

Open
NodeJSmith wants to merge 8 commits intoNabuCasa:masterfrom
NodeJSmith:fix/add_device_key_to_auth_params_if_set
Open

Fix/add device key to auth params if set#306
NodeJSmith wants to merge 8 commits intoNabuCasa:masterfrom
NodeJSmith:fix/add_device_key_to_auth_params_if_set

Conversation

@NodeJSmith
Copy link
Copy Markdown

@NodeJSmith NodeJSmith commented Jul 16, 2025

While AWSSRP was updated in a previous PR to handle device authentication support, the Cognito class and the RequestsSrpAuth class were not. This left pycognito stating that it supported this while being unable to deliver on that support.

This PR fixes this:

  • adds the four device metadata values to the init method of both classes
  • handles adding the DEVICE_KEY to the auth params during authentication, if self.device_key is set
  • handles confirming the device and setting values on Cognito instance when NewDeviceMetadata key is included in authentication response

Closes #133

Copilot AI review requested due to automatic review settings July 16, 2025 15:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for device authentication metadata throughout the library, ensuring that device keys and related parameters are properly accepted, sent in authentication requests, and handled on responses.

  • Extended constructors in both RequestsSrpAuth (utils.py) and Cognito (__init__.py) to accept device_key, device_group_key, device_password, and device_name.
  • Updated authenticate and renew_access_token in Cognito to include DEVICE_KEY in auth parameters when present.
  • Handled NewDeviceMetadata in both _set_tokens and post-auth flows to confirm devices and store returned metadata.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pycognito/utils.py Added device metadata parameters to RequestsSrpAuth init and AWSSRP call
pycognito/init.py Updated Cognito init, authenticate, renew_access_token, and _set_tokens to handle device metadata
Comments suppressed due to low confidence (2)

pycognito/init.py:732

  • Consider adding unit tests for the refresh flow to verify that DEVICE_KEY is included in AuthParameters when device_key is set, and that no device confirmation is triggered when device_key is absent.
        if self.device_key is not None:

pycognito/init.py:732

  • [nitpick] The logic to inject DEVICE_KEY into auth parameters is duplicated between authenticate and renew_access_token. Extract this into a shared helper to reduce duplication and improve maintainability.
        if self.device_key is not None:

Comment thread pycognito/__init__.py
@NodeJSmith
Copy link
Copy Markdown
Author

@ludeeus Would you be the right person to ping for a review of this PR? No rush, but want to make sure someone is aware of it.

@ludeeus
Copy link
Copy Markdown
Member

ludeeus commented Aug 1, 2025

I have asked around internally, will keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Device SRP / Device Password Verification Support

3 participants