Skip to content

Latest commit

 

History

History
84 lines (53 loc) · 1.86 KB

begin.md

File metadata and controls

84 lines (53 loc) · 1.86 KB

shopify.auth.begin

Begins the OAuth process by redirecting the merchant to the Shopify Authentication screen, where they will be asked to approve the required app scopes.

Examples

Node.js

app.get('/auth', async (req, res) => {
  // The library will automatically redirect the user
  await shopify.auth.begin({
    shop: shopify.utils.sanitizeShop(req.query.shop, true),
    callbackPath: '/auth/callback',
    isOnline: false,
    rawRequest: req,
    rawResponse: res,
  });
});

Cloudflare workers

async function handleFetch(request: Request): Promise<Response> {
  const {searchParams} = new URL(request.url);

  // The library will return a Response object
  return shopify.auth.begin({
    shop: shopify.utils.sanitizeShop(searchParams.get('shop'), true),
    callbackPath: '/auth/callback',
    isOnline: false,
    rawRequest: request,
  });
}

Parameters

shop

string | ❗ required

A Shopify domain name in the form {exampleshop}.myshopify.com.

callbackPath

string | ❗ required

The path to the callback endpoint, with a leading /. This URL must be allowed in the Partners dashboard, or using the CLI to run your app.

isOnline

bool | ❗ required

true if the session is online and false otherwise. Learn more about OAuth access modes.

rawRequest

AdapterRequest | ❗ required

The HTTP Request object used by your runtime.

rawResponse

AdapterResponse | ❗ required for Node.js

The HTTP Response object used by your runtime. Required for Node.js.

Return

Node.js

Promise<void>

This method triggers a response to the given request automatically.

Cloudflare workers

Promise<Response>

The response to be returned from the request handler.

Back to shopify.auth