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

Access token auth #91

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rdingwell
Copy link
Contributor

Part of the SMART on FHIR specification is the support for clients that operate on behave of a user when the user does not have an active session. This is accomplished through the use of the SMART offline_access scope which provides the client application with a refresh_token that can be used to obtain a new access_token. This PR enables the ability of the fhir_client to be configured with a refresh_token that can then be exchanged for an access_token.

# authorize_path -- absolute path of authorization endpoint
# token_path -- absolute path of token endpoint
# auto_configure -- whether or not to configure the oauth endpoints from the servers capability statement
# Addtional options can be passed in as supported by the OAuth2::AcessToken class
Copy link
Member

Choose a reason for hiding this comment

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

Spelling: OAuth2::AcessToken should be OAuth2::AccessToken

@jawalonoski
Copy link
Member

Very minor detail, but filename has a spelling error: test/unit/client_acess_token_test.rb should be test/unit/client_access_token_test.rb

@jawalonoski
Copy link
Member

Perhaps this is obvious, but I'm going to ask anyway... This set_auth_from_token method only works for confidential clients (i.e. they can protect a client secret), right? The more usual SMART on FHIR interactions are public clients (i.e. they cannot protect a client secret).

Thoughts on what you did hear (confidential client) with what I've done here (public client): https://github.com/mitre/scorecard_app/blob/master/app.rb#L131

@rdingwell
Copy link
Contributor Author

rdingwell commented Jun 5, 2018 via email

@arscan
Copy link
Member

arscan commented Jun 8, 2018

Sorry for taking so long to look at this @rdingwell! One issue that might come up is that the 'expires_at' field is optional in OAuth, I believe, and it isn't guaranteed to be correct, so you may not know that the current token is expired or revoked until you try the token. See: https://www.quora.com/Is-it-possible-to-know-when-an-OAuth2-token-expires

That is something I only recently learned. Expires_at is intended to be a hint... clients need to be able to handle the case of token revocation anyhow, so in practice it is easier just to handle token expiration and token revocation in the same way (look for a 401, and then try the refresh token).

I realize that we have code in the plan_executor that works in this same way, which needs to get fixed.

I'm also wondering if we should pull out the OAuth client from FHIR client, as it currently is very incomplete, and the implementation is scary (it replaces the REST client that is being used, even though the API is a bit different). It seems like we should either completely embrace OAuth and provide all the helper functions necessary to do all OAuth-related flows (such as swapping codes for access tokens). Or we should remove the OAuth dependency and have users be responsible for any OAuth handshake, and then provide them with the ability to inject whatever is necessary into authorized requests (e.g. adding headers).

As you know, OAuth is a beast, so fully supporting all OAuth would realistically mean we would just expose the OAuth gem that this is using anyhow. Or we could scope down to SMART on FHIR, but then we'd want to rename the functions to make it clear that we are only supporting the SMART profile.

Furthermore, if we extend the API to support all of OAuth, then we probably should extend it further to support all the OpenID Connect related flows as well (which is an optional part of SMART).

What do you think @jawalonoski @rdingwell ? I'm inclined to scope down what we are doing in the client in favor of having less surface area to try to maintain.

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