-
Notifications
You must be signed in to change notification settings - Fork 685
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
Validate store sessions #1612
Merged
Merged
Validate store sessions #1612
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9287e15
Check shop offline session is still valid when embedded
nelsonwittwer 04a2f53
only redirect on 401 and use better naming
nelsonwittwer a7e2677
use guard clause instead of conditional filter
nelsonwittwer 7fa7cab
redirect to shop_login if token failed
nelsonwittwer e13f5a4
update tests to match expected behavior
nelsonwittwer debe184
Changelog updates
nelsonwittwer 29199b1
raise error if not 401
nelsonwittwer 7f88b9f
better redirect test
nelsonwittwer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ module EnsureInstalled | |
|
||
before_action :check_shop_domain | ||
before_action :check_shop_known | ||
before_action :validate_non_embedded_session | ||
end | ||
|
||
def current_shopify_domain | ||
|
@@ -30,14 +31,18 @@ def current_shopify_domain | |
@shopify_domain | ||
end | ||
|
||
def installed_shop_session | ||
@installed_shop_session ||= SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain) | ||
end | ||
|
||
private | ||
|
||
def check_shop_domain | ||
redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain | ||
end | ||
|
||
def check_shop_known | ||
@shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain) | ||
@shop = installed_shop_session | ||
unless @shop | ||
if embedded_param? | ||
redirect_for_embedded | ||
|
@@ -58,5 +63,15 @@ def shop_login | |
|
||
url.to_s | ||
end | ||
|
||
def validate_non_embedded_session | ||
return if loaded_directly_from_admin? | ||
|
||
client = ShopifyAPI::Clients::Rest::Admin.new(session: installed_shop_session) | ||
client.get(path: "shop") | ||
rescue ShopifyAPI::Errors::HttpResponseError => error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we re-throw if the error isn't a 401 here? Unlikely, but may happen 🤷 |
||
redirect_to(shop_login) if error.code == 401 | ||
raise error if error.code != 401 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you think calling this
validate_session_before_embedding
would make it easier to understand this method?