-
Notifications
You must be signed in to change notification settings - Fork 474
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
Introduce the token exchange API for fetching access tokens #1254
Conversation
54dc3a3
to
5b08767
Compare
lib/shopify_api/auth/oauth.rb
Outdated
requested_token_type: RequestedTokenType, | ||
).returns(ShopifyAPI::Auth::Session) | ||
end | ||
def token_exchange(shop:, session_token:, requested_token_type:) |
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.
Could we move this into a different file? (ex: lib/shopify_api/auth/token_exchange.rb
). The purpose of the oauth.rb
file seems to be to handle the auth code flow.
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.
Ya, I see the intent for moving this into its own file and like that idea. The confusing part is token exchange still is oauth. This oauth.rb
file should probably be renamed to auth_code_flow.rb to follow remix pattern.
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 have moved the token exchange to its own module and extracted the logic to create a Session from the access token response, which is shared by both auth code and token exchange flows.
@nelsonwittwer I did not rename oauth.rb
to avoid a breaking change for now. It also follows the same naming as shopify-api-js file. But if you think that's worth a breaking change, I am happy to do it.
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.
Minor comments around file organization but the implementation looks great! Thanks for doing this! 🎉
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 this look great! We are assuming most of the work will be done on the app gem / middleware side of things. Love how simple this will be!
lib/shopify_api/auth/oauth.rb
Outdated
requested_token_type: RequestedTokenType, | ||
).returns(ShopifyAPI::Auth::Session) | ||
end | ||
def token_exchange(shop:, session_token:, requested_token_type:) |
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.
Ya, I see the intent for moving this into its own file and like that idea. The confusing part is token exchange still is oauth. This oauth.rb
file should probably be renamed to auth_code_flow.rb to follow remix pattern.
Thanks @nelsonwittwer and @rezaansyed for the review! I will address the comments right after the Christmas break, as I have a few other things to finish before that. |
7ddf785
to
00c0511
Compare
lib/shopify_api/auth/session.rb
Outdated
@@ -89,6 +89,32 @@ def temp(shop:, access_token:, &blk) | |||
end | |||
end | |||
|
|||
sig { params(shop: String, access_token_response: Oauth::AccessTokenResponse).returns(Session) } | |||
def for(shop:, access_token_response:) |
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.
Love this method!
3723a8a
to
4837de6
Compare
4837de6
to
b5dcf68
Compare
Description
This introduces the token exchange API to fetch access tokens based on the Token Exchange spec
This has been already added in
shopify-api-js
here, and we would like to make it available to Rails apps in the future as well.How has this been tested?
Unit tests are provided in the PR to cover the new method. This has also been tested internally for our app (POS channel)
Checklist: