Skip to content

Ryan morosa/bb2 5225 tie jwt verification into token endpoint asymmetric auth - #1774

Open
ryan-morosa wants to merge 20 commits into
masterfrom
ryan-morosa/bb2-5225-tie-jwt-verification-into-token-endepoint-asymmetric-auth
Open

ryan-morosa wants to merge 20 commits into
masterfrom
ryan-morosa/bb2-5225-tie-jwt-verification-into-token-endepoint-asymmetric-auth

Conversation

@ryan-morosa

@ryan-morosa ryan-morosa commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

JIRA Ticket:
BB2-5225

What Does This PR Do?

This PR ties the rest of asymmetric auth worked on from BB2-5227 into the token endpoint. We can now get an access_token_response with all the fields in it going through an asymmetric auth flow.
Summary Of Changes:

  • Tied in asymmetric auth validation into the post token endpoint
  • Added a full integration test for asymmetric auth flow and other unit tests for updating a couple other validation functions.
  • Ensured CAN did not regress

What Should Reviewers Watch For?

If you're reviewing this PR, please check for these things in particular:

Validation

  • The asymmetric auth flow end-to-end integration test and CAN integration test passing should be suffice for showing the output response.
  • You can do a make run-local CAN_INTEGRATION_TEST=true and add a print statement of the access_token_response at the end of the asymmetric auth flow test and then run pytest -s apps/fhir/bluebutton/tests/test_jwt_integration.py::test_asymmetric_auth_flow_integration_successful to see the actual token response with everything in it.
  • I haven't been able to do a manual test yet so not sure if/how we need to do that. We can probably follow the instructions here for that: https://hl7.org/fhir/smart-app-launch/STU2.2/example-app-launch-asymmetric-auth.html#step-5-access-token

What Security Implications Does This PR Have?

Please indicate if this PR does any of the following:

  • Adds any new software dependencies
  • Modifies any security controls
  • Adds new transmission or storage of data
  • Any other changes that could possibly affect security?
  • Yes, one or more of the above security implications apply. This PR must not be merged without the ISSO or team
    security engineer's approval.

Any Migrations?

  • Yes, there are migrations
    • The migrations should be run PRIOR to the code being deployed
    • The migrations should be run AFTER the code is deployed
    • There is a more complicated migration plan (downtime,
      etc)
  • No migrations

Comment thread apps/dot_ext/views/authorization.py Fixed
Comment thread apps/dot_ext/views/authorization.py Fixed
@ryan-morosa
ryan-morosa marked this pull request as ready for review October 22, 2026 04:43
@JamesDemeryNava JamesDemeryNava self-assigned this Oct 26, 2026
@jimmyfagan
jimmyfagan self-requested a review October 26, 2026 17:17
@jimmyfagan jimmyfagan self-assigned this Oct 26, 2026
@JamesDemeryNava

Copy link
Copy Markdown
Contributor

Is it okay to include logging in a different story? I think it coould be good to add to the scope of that here: https://jira.cms.gov/browse/BB2-5295

For this question, I guess it depends on when we think 5295 will be completed, and whether or not this functionality will be used before the logging is in place. If the functionality won't be used before the logging is added, I think it's fine to do it in 5295.

If the functionality will be used before 5295 is merged, i'd say we should include it here. I'm not sure exactly where asymmetric auth is at right now

@ryan-morosa

Copy link
Copy Markdown
Contributor Author

Is it okay to include logging in a different story? I think it coould be good to add to the scope of that here: https://jira.cms.gov/browse/BB2-5295

For this question, I guess it depends on when we think 5295 will be completed, and whether or not this functionality will be used before the logging is in place. If the functionality won't be used before the logging is added, I think it's fine to do it in 5295.

If the functionality will be used before 5295 is merged, i'd say we should include it here. I'm not sure exactly where asymmetric auth is at right now

yeah I think we talked about it at eng sync and it looks like we just included it as a part of 5295.

@ryan-morosa ryan-morosa changed the title Ryan morosa/bb2 5225 tie jwt verification into token endepoint asymmetric auth Ryan morosa/bb2 5225 tie jwt verification into token endpoint asymmetric auth Oct 26, 2026
@JamesDemeryNava

Copy link
Copy Markdown
Contributor

Validation steps all worked for me! Will go through the rest of the code review first thing tomorrow.

)
from apps.dot_ext.constants import (
APPLICATION_DOES_NOT_HAVE_CLIENT_CREDENTIALS_ENABLED,
APPLICATION_DOES_NOT_HAVE_THIS_AUTH_TYPE_ENABLED,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Making this comment to ensure we create the asymmetric_auth_validation waffle switch in test, sbx, and prod after this gets deployed. Probably needs to be noted in the next upcoming deployment management ticket.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That switch was already introduced right? Even if not, we can pre-emptively add the switch, might be worth doing that as part of your ticket to avoid missing it in deployment.

Comment thread apps/dot_ext/views/authorization.py Outdated
Comment thread conftest.py Outdated
Comment thread apps/fhir/bluebutton/tests/test_jwt_integration.py Outdated
Comment thread apps/dot_ext/tests/test_authorization_token.py

@JamesDemeryNava JamesDemeryNava left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validation steps work and tests look good! Left a few comments, and should probably wait for Jimmy to approve as well.

@jimmyfagan jimmyfagan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't have a chance to test this out yet, but left some comments based on looking at the changes, I have a feeling some refactor here might be useful, the token post method is kind of messy given all of the different paths that go through that method, and I like the instinct to extract some of the request validation logic, I just don't know if the validators is the best place for that.

Also to answer your question from the description, scope should be required here, in particular because we require it for authorization_code token requests in v3, and asymmetric auth should only be on v3.

Comment thread apps/dot_ext/validators.py Outdated
Comment thread apps/dot_ext/validators.py Outdated
Comment thread apps/dot_ext/views/authorization.py Outdated
Comment thread apps/dot_ext/views/authorization.py Outdated
Comment thread apps/dot_ext/views/authorization.py Outdated
Comment thread apps/dot_ext/views/authorization.py Outdated

@jimmyfagan jimmyfagan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the improvements, will keep an eye out for more re-reviews

)
from apps.dot_ext.constants import (
APPLICATION_DOES_NOT_HAVE_CLIENT_CREDENTIALS_ENABLED,
APPLICATION_DOES_NOT_HAVE_THIS_AUTH_TYPE_ENABLED,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That switch was already introduced right? Even if not, we can pre-emptively add the switch, might be worth doing that as part of your ticket to avoid missing it in deployment.

Comment thread apps/dot_ext/tests/test_authorization_token.py
@override_switch('asymmetric_auth_validation', active=True)
@override_switch('v3_endpoints', active=True)
def test_asymmetric_auth_flow_integration_successful(basic_user, create_application, create_capability):
def test_asymmetric_auth_flow_integration(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having some readability issues figuring out what these cases are. Can the parameters be named in the cases listed above to make it more clear which boolean goes to what? If not, maybe in-line comment labels or something? Probably some opportunity for us to adopt a new style guideline here. Can we add a function comment that describes what each parameter represents? In particular, token_request_fields, remove_field, add_field, field, are not very intuitive to me. These seem to work, but making them more human readable I think helps maintain, troubleshoot, and add new tests when needed.

@ryan-morosa ryan-morosa Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

totally fair - I'll try to see if there's a better way/add some doc strings

# client_assertion and client_assertion_type and they are only
# approved for asymmetric auth
# (An Asymmetric-Only app has a jwks_uri but its client_secret_plain field is completely empty)
is_asymmetric_only = bool(app.jwks_uri and not app.client_secret_plain)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if we ever hit this case? I think it remains to be seen how an asymmetric-only app would be set, but as it is right now, it would still have a client secret since the client secret is set when the app is created. I suspect we may eventually want to add something like this if that changes, but as it is now, I don't know that this is necessary.

@ryan-morosa ryan-morosa Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Yeah I though it would be good to add this piece after working on https://jira.cms.gov/browse/BB2-5229 since it looked like we might lean toward no client secret for asymmetric auth being set but I can remove it and make it a separate story if we think that's better. Might've scope creeped this story a bit.

This branch has not been deployed

No deployments
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.

4 participants