-
Notifications
You must be signed in to change notification settings - Fork 698
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
Implement JWT callback endpoint #951
Conversation
Is there a reason we prefer not to override the old callback endpoint to handle both cases based on whether Would that be easier since we then wouldn't have to keep track of both urls. |
I don't think we can do that because the existing callback endpoint has to run for the initial install (to get the shop token), even if |
def jwt_callback | ||
if valid_jwt_auth? | ||
create_user_session_from_jwt_callback | ||
head(:ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use head(:no_content) instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather stick with OK because I think we're likely to add some content later, and I don't want apps to break when the status code switches from 204 => 200.
@@ -24,8 +24,31 @@ def callback | |||
end | |||
end | |||
|
|||
def jwt_callback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only for user tokens, should we call this user_callback
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's more tightly coupled to the jwt
aspect than the user
aspect, since the other callback endpoint can also handle user tokens.
Ok, so there are some issues with the current approach :) Here's what I've discovered:
I'll work on this later today and we can see how it looks and if we like it. |
LGTM. |
I'm reluctant to do that because some apps might use other bearer tokens in parts of their app. I think rejecting the request is more of a controller concern. |
jwt_callback | ||
return | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be if
/elsif
/else
blocks rather than having the early return?
login_shop | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this block of code be extracted out for single-level-of-abstraction reasons? It looks like we're doing that with jwt_callback
above, and it seems nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried cleaning this up for clarity, take a look and see what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tophatted it with Adi and works as expected 👍
@leleabhinav are you OK with where this ended up? |
OAuth returns 'id' not 'shopify_user_id'
This decouples retrieving the JWT data from the Rails controller layer so that we can use this data when making decisions in the omniauth middleware.
It's a bit of a pain to have two separate callback paths in omniauth. There is a callback_path option, and it does take a block, but I'm a little unclear about how it knows how to start the normal OAuth flow if you use a block for this option. To keep things simple I went with the single callback endpoint.
Technically it does more than we need, but we protect against the other paths elsewhere, and this simplies the logic overall.
|
@Shopify/platform-dev-tools-education I'm ready for a review on this when you have a chance :) Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and an interesting approach. I wonder if in the future, the middleware could be extracted so that we could support more than just rails.
For sure, I'm thinking we could pretty easily make that move if/when we think it would be useful. |
Goals
When we receive an OAuth callback with a JWT in the headers, we want to do two things:
Implementation
shopify_app
controller stuff.