Skip to content

jprivillaso/shopify-node-auth

Repository files navigation

Shopify App Authentication with Nodejs

This is a boilerplate to be used if you want to create an embedded application for Shopify.

Project structure

This project includes a NodeJs server that will deliver static files at a specified port. When creating embedded applications at Shopify you need to create an Oauth flux in order to authenticate and install the app in a Shopify Store.

app.js will contain the server configuration and will serve static files from the public folder.

Pay special attention to the config folder as it will contain all the information needed to authenticate at Shopify.

OAuth data is contained at auth.development and auth.production. Two files exist because some of these properties can be different for different environments.

At the routes folder you can define more routes to access Shopify APIS, however this will need additional configuration. After the installation of the app, a permanent token is generated for that shop, and you need to store it somewhere.

If you want to know more about how the Authentication works, please visit the official documentation.

OAuth Process

  1. When a request to the / route is sent, the application will check if the application has been installed and has previous granted access, or simply it will render an HTML file.

  2. The first time a user calls your shop, it will trigger the Authentication flux, generating a nonce, and then redirecting to an URI generated by a Shopify method

shopifyToken.generateAuthUrl(shopifyToken.shop, undefined, nonce);

  1. This will open a login prompt in the browser in which the user will need to enter his login and password.

  2. After successfully login, the user will be asked for permission to install the application.

  3. After the confirmation, a recurring charge will be created. This recurring charge was set by default to test which indicates that it won't charge the user for this and that it's a test install.

  4. After accepting the charges, the app will be installed and redirected to the specified URL at the Partner's Shop App configuration.

  5. After that, you will be ready to access your app under the Apps menu inside your Shop.

Deploy

There are so many tools that can be used for deploying small apps, however if you want to deploy an application in a matter of minutes, wedeploy can be a good choice.

Additional configuration will be nedded from the Shopify Partners account, under Apps menu.

Testing the App

After deploying your application in your server, you should call this URL at your browser

https://your-server-domain.com?shop=your-shop-name.myshopify.com

This will simulate a real installation from the Shopify Store link when the user clicks at the install button.