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

Add session token concern #986

Merged
merged 1 commit into from
May 21, 2020
Merged

Conversation

theundeadmonk
Copy link
Contributor

This PR adds a concern that can be used in an unauthenticated controller.
It does the following

  • Adds a before action to check if the passed in shop domain is valid
  • Adds a before action to check if the passed in shop is installed
    Both the before actions redirect to login in case of failure

end

def check_shop_known
@shop = Shop.find_by(shopify_domain: @shopify_domain)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should be accessing this data via SessionRepository.retrieve_shop_session_by_domain. How the fetch logic is implemented is a detail that's hidden behind the interface.

# frozen_string_literal: true

module ShopifyApp
module DomainProtection
Copy link
Contributor

Choose a reason for hiding this comment

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

Just want to call attention to the name for other reviewers. We wanted to name this something that indicates its responsibility and reflects that it would be used instead of LoginProtection. Does this name do that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe RequireKnownShop or something would be more clear what it does?


def check_shop_known
@shop = Shop.find_by(shopify_domain: @shopify_domain)
redirect_to("#{ShopifyApp.configuration.login_url}?shop=#{@shopify_domain}") unless @shop
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a return_to parameter so that the redirect returns us back to the page it was last at and not always the homepage? Email folks added a PR fix for this yesterday: https://github.com/Shopify/email/pull/4746

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rezaansyed I think if the shop doesn't exist we'd want them to go through the login flow again, right?
Email does that because it is trying to masquerade as being part of Shopify and not an app so they redirect to the marketing section.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the return_to would be the path the user gets taken to within the app iframe after the login flow finishes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Okay, I'll make the changes.

@theundeadmonk theundeadmonk force-pushed the add-session-token-concern branch 2 times, most recently from 45f987c to 89b9048 Compare May 19, 2020 13:08
url.query = URI.encode_www_form(
shop: params[:shop],
return_to: request.fullpath,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird indentation here

redirect_url.query = URI.encode_www_form(
shop: shopify_domain,
return_to: request.fullpath,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird indentation

end

def check_shop_known
@shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good now!

retrieve_shop_session_by_domain ~> retrieve_shop_session_by_shopify_domain

@theundeadmonk
Copy link
Contributor Author

🎩 on a test app

@theundeadmonk theundeadmonk merged commit f623184 into master May 21, 2020
@theundeadmonk theundeadmonk deleted the add-session-token-concern branch May 21, 2020 11:36
@rezaansyed rezaansyed temporarily deployed to rubygems June 1, 2020 17:31 Inactive
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.

None yet

6 participants