Skip to content

Commit

Permalink
Merge branch 'main' into klenotiw/add-log-levels
Browse files Browse the repository at this point in the history
  • Loading branch information
klenotiw committed Nov 15, 2022
2 parents 8d6547c + e297ef1 commit 38976f2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased
* Fixes a bug with `EnsureAuthenticatedLinks` causing deep links to not work [#1549](https://github.com/Shopify/shopify_app/pull/1549)
* Ensure online token is properly used when using `current_shopify_session` [#1566](https://github.com/Shopify/shopify_app/pull/1566)
* Added debug logs, you can read more about logging (here)[./docs/logging.md]. [#1545](https://github.com/Shopify/shopify_app/pull/1545)
* Log a deprecation warning for the use of incompatible controller concerns [#1560](https://github.com/Shopify/shopify_app/pull/1560)

21.2.0 (Oct 25, 2022)
----------
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

This gem builds Rails applications that can be embedded in the Shopify Admin.

[Introduction](#introduction) |
[Requirements](#requirements) |
[Usage](#usage) |
[Documentation](#documentation) |
[Introduction](#introduction) |
[Requirements](#requirements) |
[Usage](#usage) |
[Documentation](#documentation) |
[Contributing](/CONTRIBUTING.md) |
[License](/LICENSE)

Expand All @@ -22,15 +22,12 @@ This gem includes a Rails engine, generators, modules, and mixins that help crea
<!-- This section is linked to in `templates/shopify_app.rb.tt`. Be careful renaming this heading. -->
## Requirements

> **Rails compatibility**
> * Use Shopify App `<= v7.2.8` if you need to work with Rails 4.
To become a Shopify app developer, you will need a [Shopify Partners](https://www.shopify.com/partners) account. Explore the [Shopify dev docs](https://shopify.dev/concepts/shopify-introduction) to learn more about [building Shopify apps](https://shopify.dev/concepts/apps).

This gem requires that you have the following credentials:

- **Shopify API key:** The API key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).
- **Shopify API secret:** The API secret key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).
- **Shopify API key:** The API key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).
- **Shopify API secret:** The API secret key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).

## Usage

Expand All @@ -40,22 +37,22 @@ This gem requires that you have the following credentials:
rails new my_shopify_app
```

2. Add the Shopify App gem to `my_shopify_app`'s Gemfile.
2. Add the Shopify App gem to the app's Gemfile:

```sh
bundle add shopify_app
```

3. Create a `.env` file in the root of `my_shopify_app` to specify your full host and Shopify API credentials:
3. You will need to provide several environment variables to the app.
There are a variety of way of doing this, but for a development environment we recommended the [`dotenv-rails`](https://github.com/bkeepers/dotenv) gem.
Create a `.env` file in the root of your Rails app to specify the full host and Shopify API credentials:

```sh
HOST=http://localhost:3000
SHOPIFY_API_KEY=<Your Shopify API key>
SHOPIFY_API_SECRET=<Your Shopify API secret>
```

> In a development environment, you can use a gem like `dotenv-rails` to manage environment variables.
4. Run the default Shopify App generator to create an app that can be embedded in the Shopify Admin:

```sh
Expand All @@ -74,9 +71,14 @@ rails db:migrate
rails server
```

7. Install the app by visiting the server's URL (e.g. http://127.0.0.1:3000) and specifying the subdomain of the shop where you want it to be installed to.
7. Within [Shopify Partners](https://www.shopify.com/partners), navigate to your App, then App Setup, and configure the URLs, e.g.:

* App URL: http://locahost:3000/
* Allowed redirection URL(s): http://localhost:3000/auth/shopify/callback

8. Install the app by visiting the server's URL (e.g. http://localhost:3000) and specifying the subdomain of the shop where you want it to be installed to.

8. After the app is installed, you're redirected to the embedded app.
9. After the app is installed, you're redirected to the embedded app.

This app implements [OAuth 2.0](https://shopify.dev/tutorials/authenticate-with-oauth) with Shopify to authenticate requests made to Shopify APIs. By default, this app is configured to use [session tokens](https://shopify.dev/concepts/apps/building-embedded-apps-using-session-tokens) to authenticate merchants when embedded in the Shopify Admin.

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ We look forward to working with all security researchers and strive to be respec

## Receiving Security Updates

To recieve all general updates to vulnerabilities, please subscribe to our hackerone [Hacktivity](https://hackerone.com/shopify/hacktivity)
To receive all general updates to vulnerabilities, please subscribe to our hackerone [Hacktivity](https://hackerone.com/shopify/hacktivity)
8 changes: 8 additions & 0 deletions app/controllers/concerns/shopify_app/require_known_shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ module RequireKnownShop
include ShopifyApp::RedirectForEmbedded

included do
if ancestors.include?(ShopifyApp::LoginProtection)
ActiveSupport::Deprecation.warn(<<~EOS)
We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name},
which may lead to unpredictable behavior. In a future release of this library this will raise an error.
EOS

end

before_action :check_shop_domain
before_action :check_shop_known
end
Expand Down
2 changes: 1 addition & 1 deletion docs/Upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Shopify API session, or `nil` if no such session is available.

#### Setting up `ShopifyAPI::Context`

The `shopify_app` initializer must configure the `ShopifyAPI::Context`. The Rails generator will generate a block in the `shopify_app` initializer. To do so manually, you can refer to `after_initialize` block in the [template]((https://github.com/Shopify/shopify_app/blob/main/lib/generators/shopify_app/install/templates/shopify_app.rb.tt).
The `shopify_app` initializer must configure the `ShopifyAPI::Context`. The Rails generator will generate a block in the `shopify_app` initializer. To do so manually, you can refer to `after_initialize` block in the [template](https://github.com/Shopify/shopify_app/blob/main/lib/generators/shopify_app/install/templates/shopify_app.rb.tt).

## Upgrading to `v18.1.2`

Expand Down
7 changes: 7 additions & 0 deletions lib/shopify_app/controller_concerns/login_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module LoginProtection
include ShopifyApp::SanitizedParams

included do
if ancestors.include?(ShopifyApp::RequireKnownShop)
ActiveSupport::Deprecation.warn(<<~EOS)
We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name},
which may lead to unpredictable behavior. In a future release of this library this will raise an error.
EOS
end

after_action :set_test_cookie
rescue_from ShopifyAPI::Errors::HttpResponseError, with: :handle_http_error
end
Expand Down
26 changes: 26 additions & 0 deletions test/controllers/concerns/require_known_shop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,30 @@ def index

assert_response :ok
end

test "detects incompatible controller concerns" do
assert_deprecated(/incompatible concerns/) do
Class.new(ApplicationController) do
include ShopifyApp::RequireKnownShop
include ShopifyApp::LoginProtection
end
end

assert_deprecated(/incompatible concerns/) do
Class.new(ApplicationController) do
include ShopifyApp::RequireKnownShop
include ShopifyApp::Authenticated # since this indirectly includes LoginProtection
end
end

assert_deprecated(/incompatible concerns/) do
authenticated_controller = Class.new(ApplicationController) do
include ShopifyApp::Authenticated
end

Class.new(authenticated_controller) do
include ShopifyApp::RequireKnownShop
end
end
end
end
1 change: 0 additions & 1 deletion test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
include ShopifyApp::LoginProtection
end
3 changes: 3 additions & 0 deletions test/dummy/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

class HomeController < ApplicationController
include ShopifyApp::EmbeddedApp
include ShopifyApp::RequireKnownShop

def index
"index"
end
Expand Down
9 changes: 9 additions & 0 deletions test/shopify_app/controller_concerns/login_protection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ class LoginProtectionControllerTest < ActionController::TestCase
end
end

test "detects incompatible controller concerns" do
assert_deprecated(/incompatible concerns/) do
Class.new(ApplicationController) do
include ShopifyApp::LoginProtection
include ShopifyApp::RequireKnownShop
end
end
end

private

def assert_fullpage_redirected(shop_domain, _response)
Expand Down

0 comments on commit 38976f2

Please sign in to comment.