Overview
Theauth API provides methods for authenticating your Shopify app using OAuth, token exchange, and various token management flows.
Access the auth API through your configured Shopify instance:
begin()
Initiates the OAuth authorization flow by redirecting the merchant to Shopify’s authorization page.Signature
Parameters
The shop domain. For example:
exampleshop.myshopify.com.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.Defines if the session is online or offline.Learn more about OAuth access modes.
Returns
Returns aPromise<AdapterResponse> that resolves to an HTTP redirect response (status 302) to Shopify’s OAuth authorization page.
Example
Notes
This function sets a secure, signed cookie containing the OAuth state parameter for CSRF protection.
Cannot be used with custom store apps (
isCustomStoreApp: true). Will throw PrivateAppError.callback()
Completes the OAuth authorization flow by exchanging the authorization code for an access token.Signature
Parameters
Whether the access token should be expiring.Learn more about Expiring Access Tokens.
Returns
Returns aPromise<CallbackResponse> with:
Response headers (includes Set-Cookie for non-embedded apps).
The created session object containing:
id- Session IDshop- Shop domainstate- OAuth stateaccessToken- Access tokenscope- Granted scopesexpires- Expiration date (for online sessions)isOnline- Whether this is an online sessiononlineAccessInfo- Online access info (if online session)
Example
Errors
Throws the following errors:CookieNotFound- OAuth state cookie not foundInvalidOAuthError- Invalid OAuth callback (HMAC validation failed)BotActivityDetected- Request initiated by a bot
tokenExchange()
Exchanges a session token for an access token. Recommended for embedded apps using App Bridge.Signature
Parameters
The shop domain.
The session token from Shopify App Bridge.
The type of token to request:
RequestedTokenType.OnlineAccessToken- Online access tokenRequestedTokenType.OfflineAccessToken- Offline access token
Whether the access token should be expiring.
Returns
The created session object.
Example
clientCredentials()
Obtains an access token using the client credentials flow. Used for admin-level API access.Signature
Parameters
The shop domain.
Returns
The created session object with admin-level access.
Example
refreshToken()
Refreshes an expired access token using a refresh token.Signature
Parameters
The shop domain.
The refresh token from the previous session.
Returns
A new session object with a fresh access token.
Example
migrateToExpiringToken()
Migrates a non-expiring access token to an expiring token.Signature
Example
Utility Functions
nonce()
Generates a cryptographically secure random nonce.safeCompare()
Performs constant-time string comparison to prevent timing attacks.getEmbeddedAppUrl()
Gets the embedded app URL for the current request.buildEmbeddedAppUrl()
Builds an embedded app URL from components.Types
RequestedTokenType
OnlineAccessInfo
OfflineAccessInfo
Notes
For embedded apps, use
tokenExchange() instead of the traditional OAuth flow for better user experience.Always store sessions securely in your database. Never expose access tokens to the frontend.
Use offline access tokens for background jobs and webhooks. Use online access tokens for user-specific operations.