Giter Club home page Giter Club logo

next-gen-auth-app-demo's Introduction

App Bridge Authentication

A demo app created using Rails, React, and App Bridge for the Shopify tutorial Build a Shopify app with Rails, React, and App Bridge.

Quick Start

To run this app locally, you can clone this repository and do the following.

  1. Create a .env file to specify this app's API key and API secret key app credentials that can be found in the Shopify Partners dashboard.
SHOPIFY_API_KEY=<The API key app credential specified in the Shopify Partners dashboard>
SHOPIFY_API_SECRET=<The API secret key app credential specified in the Shopify Partners dashboard>
APP_URL=<The app URL specified in the Shopify Partners dashboard>

Note: If you do not have an API key or an API secret key, see the following sections of the Build a Shopify App with Node and React guide.

Important: This guide names its API secret key environment variable SHOPIFY_API_SECRET_KEY rather than SHOPIFY_API_SECRET. The Shopify App gem uses the latter.

  1. Expose your dev environment
  2. Get a Shopify API Key and Shopify API secret key
  3. Add the Shopify API Key and Shopify API secret key
  1. Run the following to install the required dependencies.
$ bundle install
$ yarn install
$ rails db:migrate
  1. Ensure ngrok is running on port 3000.
$ ngrok http 3000

Note: This port number is arbitrary - you may choose to specify the port number you plan to listen to this app on.

  1. Run the following to start the app.
$ rails s
  1. Install and open this app on a shop. Requests to authenticated resources, like the GraphqlController, should now be secured with an Authorization: Bearer <session token> header.

App dashboard

Above: Example text received from a protected /graphql endpoint

App requests

Above: Requests made to the protected /graphql endpoint are automatically authorized using a JWT token

next-gen-auth-app-demo's People

Contributors

borahm avatar francisbeaudoin avatar msitkovets avatar nabeelahsen avatar rezaansyed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-gen-auth-app-demo's Issues

Webpacker can't find application Error

Hi,

I am getting this error when I try to serve the project. Can you please advise?

Webpacker can't find application in /Users/Shared/Projects/next-gen-auth-app-demo/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
  "entrypoints": {
  }
}

Suggest: Replace `stylesheet_link_tag` with `stylesheet_pack_tag` in `app/views/layouts/application.html.erb`

I spent a good amount of time trying to figure out why my styles imported in the JS(X) files were not being loaded in production.

The issue was explained in the second point here:
https://github.com/rails/webpacker/blob/master/docs/css.md#css-sass-and-scss

I missed that because I copy-pasted the layout file from this project.

This project also uses error-prone way to include Shopify Polaris styles. It loads styles from unpkg CDN, requesting a specific version (all good here). However, this version number is hardcoded in the erb file, while there's also Shopify Polaris package version in package.json.
To avoid this, you can import Shopify Polaris styles in your JS(X) files like so:
import '@shopify/polaris/dist/styles.css'

What I actually ended up doing was to have app/javascript/packs/application.js and app/javascript/packs/application.scss as per webpack(er) documentation: https://github.com/rails/webpacker/blob/master/docs/css.md#importing-css-as-a-multi-file-pack-webpacker-v5

The app/javascript/packs/application.scss then imports Shopify Polaris: @import '@shopify/polaris/dist/styles.css';

Nice example but can I base my production front-end on this?

Does this work with shopify_app v.18? With Polaris? With react routing? With app_bridge react utils? So many gaps and unknowns! Why should I invest time and base my app on an example "of the current moment" over a front-end landscape that seems to be changing drastically every couple of months?

Step 5: Install and open this app on a shop

I have followed the steps to install the sample app named "mlbrains-react". I am running both ngrok and "rails s" in 2 screens.
As per step 5, I need to "Install and open this app on a shop".

However, when I search for the app it is not available on the store. That is probably obvious as this is created as a private app.

Can you suggest how this issue can be resolved.
Screenshot 2021-02-25 175647

Can Action Cable be used?

I've read in the Shopify documentation that app developers have to avoid setting cookies, however the rails documentation for Action Cable is pretty clear that cookies are necessary to authenticate Action Cable connections. I see in the example app here that action cable is stubbed but not setup. Is this because it's just not possible to use in the app eco system? Thanks!

Content-Security-Policy: frame-ancestors

Thanks a lot for the demo app. I’ve submitted an app for Shopify prescreening and got rejected two times due to missing ‘Content-Security-Policy: frame-ancestors https://example.myshopify.com https://admin.shopify.com;’.

I’ve noticed you added it via /initializers/content_security_policy.rb like:

initial_frame_ancestors = [:https, "*.myshopify.com", "admin.shopify.com"]

def current_domain
  @current_domain ||= (params[:shop] && ShopifyApp::Utils.sanitize_shop_domain(params[:shop])) ||
    request.env["jwt.shopify_domain"] ||
    session[:shopify_domain]
end

frame_ancestors = lambda { current_domain ? [ current_domain, "admin.shopify.com" ] : initial_frame_ancestors }

Rails.application.config.content_security_policy do |policy|
  policy.default_src(:https, :self)
  policy.style_src(:https, "cdn.shopifycloud.com")
  policy.script_src(:https, "cdn.shopifycloud.com")
  policy.img_src(:self, :https, :data, "cdn.shopifycloud.com")
  policy.upgrade_insecure_requests(true)
  policy.frame_ancestors(frame_ancestors)
end

Meanwhile, I was trying to achieve that, assigning policy in AuthenticatedController, like:

content_security_policy do |p|
  p.frame_ancestors -> { "https://#{shop_session.domain} https://admin.shopify.com" }
end

Can you confirm that your approach is recommended and the app won’t be rejected during prescreening due to missing ‘Content-Security-Policy: frame-ancestors https://example.myshopify.com https://admin.shopify.com;’?

I’ve tried to find info on that in docs and Shopify dev forums, but no clues on this topic out there or at least I wasn’t able to find them.

Cannot install app

I've followed the tutorial but when I try to install the app on a development store, I get the error Oauth error invalid_request: The redirect_uri is not whitelisted with http status code 400.

I've configured the whitelist url in my partner dashboard according to the tutorial.

I know this is a demo but...

I am curious why this demo chose to brute force graphql instead of using the Shopify API gem?

Seems kind of weird when so much configuration is already baked in for shopify_api... Just curious.

As a consumer of the Shopify App and API gem, and the ecosystem, I deeply underwhelmed by the move to JWT tokens as a thing to solve the broken browser embedded app issue, as put forth so far. Reading the code shows me gaping chasms to cross. I guess this is a group effort and eventually, some effort will result in showing off how everything works together.

It is cool that you show off Apollo for those that use Apollo, and I really liked that you also showed Axios off, as I only use that. So there are hints in this repo as to how it might all work and come together, but it is still not very clear how to architect the combo of the Shopify App with JWT and the Shopify API together. Close. But not quite. For me anyway. I guess more study is needed.

React route is not working with Session Auth

When I try a direct link in URL like /app/settings, its working fine but when I am trying to go from React route path, it's not going to the correct page and showing me the login page, this is my route code - https://d.pr/i/bvZovk

I think its a session auth problem. Is there any way to pass session in react-router-dom

With getSessionToken I use Axios - https://d.pr/i/tVos6U to get data but how can I pass the auth session to route?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.