-
Notifications
You must be signed in to change notification settings - Fork 61
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
oauth2
Refresh Token Utilization
#134
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR @progmem! The OAuth2 portion of this library needs some work and appreciate the contribution. I'm not sure if you've looked at PR #91, but there is some discussion and that might be helpful and some unit tests that might inform how we can fix the existing unit tests or add a couple more. I'd like to get @arscan's thoughts too as he was involved in those discussions. This PR highlights an issue with the Fixing that test will require stubbing out a few HTTP requests. It would also be nice to have a few small tests with similar stubs to exercise the refresh. #91 could give a lead on how to get started. The code overall looks good to me (having to check for |
@radamson I haven't looked at #91 up until this point. Looking over it and reading the last part of your comment, I didn't realize that
I actually wrote a module that handled a similar process, but only on a single method. I should be able to apply it to the base code in a way that would give us this kind of behavior. |
@radamson Looking over the code in tandem with the test, there's a bit of a problem in how the test is currently handling things. There's existing tests immediately above
The alternative to modifying the test would be to simply return on the new |
@progmem Correct that test does have issues which is what I was trying to say with:
in my above comment. Good point that we'll have to catch a different set of exceptions though, although that's pretty unfortunate. Maybe eventually we'll want to be able to abstract that away to properly encapsulate the underlying implementations, but that is probably better addressed in its own PR. |
I generally agree with the strategy you have proposed for handling expired tokens with the updated considerations for scenarios when the expiration time is not present. I think it would be good to have that as some sort of wrapper around the existing operations so that it can be easily applied to them all while maintaining the separation of concerns between the authorization and restful interactions. |
@radamson With regards for a wrapper, I actually started work on a bit of a refactor on the RESTful calls to allow such a situation. My goal in that refactor is to have each of the REST verbs call a method for triaging out to separated modules. The advantage of this is that we can better incorporate the OAuth2 token refresh logic in a way that would allow us to pre-emptively refresh when In theory this could allow us to throw our own exceptions for testing, for example having This does present itself as a "scope creep" for this specific PR, which is to handle OAuth2 refresh tokens, but at the same time I believe it could put the codebase in a better position. My inclination is to close this PR, open one up for the separate refactor (which would also address the testing concerns that have been brought up), then open a separate one for the improved OAuth2 refresh methodology. Let me know what your thoughts are on this. |
@radamson I managed to finish up the refactoring work that I mentioned above in a separate branch. I essentially separated out the code for handling the REST verb calls into two different subclasses, which are utilized based on whatever I did this as a separate branch primarily because in the context of this PR, this is total scope creep. There's a couple of additional fixes in that work that would fall outside of this PR:
If it seems reasonable, I'd like to close this PR and open a new one based on this new branch of work. I believe this work would also put the codebase in a better position to integrate the work from #91 in, though I'll leave that for discussion. |
Awesome @progmem. I haven't had a chance to go through the refactoring work you've done, but this type of work is something we've been talking about for a while so I'm happy to see it! I'm ok with opening a new PR for that work so we can have a place to host discussion, but it might be a little preemptive to close this one considering the scope creep (although I suppose we could always reopen it). I'll probably have a better sense once I've had a chance to read through you're changes. One thing that might be worth thinking about in the meantime, and what I'll be thinking about when I'm reviewing, is how we'll ultimately want the API and the implementation to work. I was having a discussion with @arscan and @jawalonoski who brought up some ideas that we may want to at least consider with this refactor: i.e.
Simplifying the implementation to only have a single client dependency would help alleviate some of the issues we've been seeing and (hopefully) make future maintenance easier. Thoughts on this @progmem? I'll take a look at the refactoring work you've done and thanks again for the PRs! |
@radamson I'll go ahead and open a new PR for the refactor work at the very least, that way we can invite the discussion about the API and the OAuth2/RestClient implementations into it. I'll post my thoughts to that PR as well, primarily since this current discussion would be better-suited for it. |
The following PR allows for the leveraging of refresh tokens when using OAuth 2.0 authentication. If a refresh token is available, it will be utilized once the current access token has expired.
Given the current best practices for SMART on FHIR EHRs , this seems like it would be useful for anyone utilizing OAuth 2.0 in scenarios where you may have a persistent thread or long-running process (for example, a process taking incoming data from one system and importing it into another via the FHIR APIs).