Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-2254 Implement token introspection #112

Merged
merged 9 commits into from
Dec 7, 2023
Merged

Conversation

arscan
Copy link
Contributor

@arscan arscan commented Oct 19, 2023

Summary

Adds token introspection capabilities per openid token introspection standard

Testing guidance

I recommend that @alisawallace verifies the token introspection stuff, and that @Jammjammjamm or @dehall just does a quick check to make sure that I didn't mess up any of the other stuff. g10 tests seem to pass still when i run this (and running g10 helped me identify a problem with the capstatement).

For testing against the new token introspection tests: I recommend:

In the smart app launch test kit, assuming a 'ruby development setup', do the following:

  • remove from .env and .env.development the COMPOSE_PROFILES=keycloak line -- i was having a little bit of trouble with this interferring with the reference server when running it at the same time, so lets just not start keycloak any more.
  • inferno services start to start the background services (db, redis, etc)
  • inferno start to start the application
  • visit http://localhost:4567
  • select STU2 of the smart app launch
  • select 'Inferno Reference Server' preset
  • Run 'standalone launch' tests
  • change endpoint to http://localhost:8080/reference-server/r4
  • click through and the tests should pass, except for TLS
  • In test 1.1.01 (discovery), take a look at the output tab and grab the token introspection url from there (will be http://localhost:8080/reference-server/oauth/token/introspect)
  • run the token introspection test
  • appropriately split up the URL so that the current inputs work (note how we will want a single introspection url input insteead of having them split up in two inputs later)
  • select the 'standalone test' to get the bearer token from
  • turn off 'include scope' thing for keycloak on the bottom
  • run the group tests
  • You'll get blocked by the fact that the token is not a JWK, which is not a valid requirement as we had discussed
  • Remove a bunch of code in that test so that it really just verifying that the POST returns 'active = true'
  • restart the inferno tests, it should now pass

This should allow us to pivot over to a more realistic test scenario where we aren't spread across two different auth servers in the test kit.

@arscan arscan requested a review from alisawallace October 19, 2023 20:47
@arscan arscan changed the title Initial token introspection with incomplete fields. FI-2254 Initial token introspection with incomplete fields. Oct 19, 2023
@alisawallace
Copy link

@arscan confirming that this implementation is working with the instructions you provided. Thanks for getting this set up!

@arscan arscan changed the title FI-2254 Initial token introspection with incomplete fields. WIP FI-2254 Initial token introspection with incomplete fields. Nov 6, 2023
@arscan arscan changed the title WIP FI-2254 Initial token introspection with incomplete fields. FI-2254 Implement token introspection Dec 1, 2023
@arscan arscan force-pushed the fi-2227-token-introspection branch from 14e2a2d to c6daa31 Compare December 1, 2023 22:00
@arscan arscan force-pushed the fi-2227-token-introspection branch from c6daa31 to 72191c2 Compare December 1, 2023 22:05
@arscan arscan requested review from Jammjammjamm and dehall December 1, 2023 22:33
Copy link
Contributor

@dehall dehall left a comment

Choose a reason for hiding this comment

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

Looked through the code and I don't have any real concerns, just a couple trivial notes. I want to run through the g10 test kit with this myself tomorrow though

Token customBearerToken = new Token(customBearerTokenString,
FhirReferenceServerUtils.getScopesListByScopeString(CUSTOM_BEARER_TOKEN_SCOPE_STRING));
customBearerToken.setClientId("SAMPLE_CLIENT_ID");
customBearerToken.setExp(java.time.Instant.now().getEpochSecond() + expiresIn);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is really better but you could leverage the java time libraries to do the time math:

      customBearerToken.setExp(Instant.now().plus(4, ChronoUnit.MONTHS).getEpochSecond());

}

} catch (TokenNotFoundException tokenNotFoundException) {
// This doesn't feel quit right, but am staying consistent
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading up a little on the token introspection endpoint, this seems fine to me. I'm not sure even logging the exception is that necessary.

Copy link

@alisawallace alisawallace left a comment

Choose a reason for hiding this comment

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

Works well for me! I tested it with both a public client ID and a confidential client ID and secret, everything (except TLS tests of course) passed and ref server output looks good.

Choose a reason for hiding this comment

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

The Token Introspection Endpoint URL is not listed here but may be worth including. I know it's not strictly necessary since it's included as part of the .well-known endpoints, but including it would allow someone to run only group 3 Token Introspection without first having to run Group 1 to get the endpoint. Ultimately up to you though!

@arscan arscan merged commit 603bc87 into main Dec 7, 2023
1 check passed
@arscan arscan deleted the fi-2227-token-introspection branch December 7, 2023 21:10
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.

3 participants