What you need to know about managing auth for your Shopify app

Getting authentication right in Shopify apps is crucial – it's the foundation of your app's security and reliability. But Shopify doesn’t make it easy. Between OAuth flows, session tokens, and API authentication, there's a lot to consider, so let's break down what you actually need to know to handle auth properly.
Understanding Shopify's auth landscape
If you’ve been trying to get OAuth working and are having trouble, you’re not alone. We constantly hear from developers about how they spent days or even weeks trying to get it working, only to eventually give up.
Multi-tenant apps are never simple, and Shopify apps are required to handle several types of authentication before they can be used safely. First, there's the OAuth flow that occurs when a merchant installs your app. Then there's ongoing API authentication for securely handling backend requests to Shopify. And finally, there's session management for merchants using your app's interface.
Each of these has its own challenges and requirements. OAuth needs to be secure and reliable, API authentication needs to handle rate limits and token refresh, and session management needs to work within Shopify's embedded app constraints.
(Of course, if you want to skip the headaches and just get straight to building your app, Gadget will handle Shopify OAuth for you. And it’s free.)
Core authentication components
From a technical perspective, the OAuth flow is your app’s first interaction with a merchant's store. You need to validate the installation request, securely exchange an authorization code for access tokens, and safely store those credentials. Getting this right is imperative, as any mistakes here compromise your app's security from the start — which is why Shopify is so strict about how this is set up.
If you want your app to have a frontend embedded in the admin portal (which, of course you do) then you’ll have to deal with session tokens, which require special handling in Shopify's embedded admin. You can't use regular cookies anymore – Shopify requires you to use their session tokens for embedded apps. This means implementing proper token validation and refresh logic.
API authentication isn't just about adding access tokens to requests. You need proper error handling for expired tokens, rate limits, and API disruptions. Your app should gracefully handle these scenarios without breaking the merchant experience.
Common authentication pitfalls
Many developers stumble on similar authentication issues, so if you're getting stuck, these are the big ones to watch for.
Not validating installation requests properly. Every OAuth request needs HMAC validation to ensure it actually came from Shopify. Skipping this validation leaves your app open to unauthorized installations. The validation process requires checking the hmac parameter against a hash of all other parameters, sorted alphabetically. Missing even small details like parameter sorting can lead to validation failures.
Using cookies for session management in embedded apps. This won't work reliably anymore – you need to use Shopify's session tokens instead. The old approach using cookies will fail in various browsers and scenarios, particularly with increased privacy restrictions and third-party cookie blocking. Session tokens need to be passed with each request and validated server-side.
Storing access tokens insecurely. Never expose these in client-side code, URLs, or logs. Access tokens should be securely stored server-side and only used for backend API calls. If tokens are leaked, malicious actors could make unauthorized API calls on behalf of merchants. Consider using encrypted storage for tokens and implementing proper key rotation.
Improper error handling during authentication flows. OAuth flows can fail for many reasons – network issues, invalid parameters, expired tokens. Your app needs to handle these gracefully and provide clear feedback to users. Implement proper logging to track auth failures and their causes.
Building reliable authentication
Your authentication implementation needs to handle various edge cases beyond the happy path.
Token refresh needs to work reliably. When access tokens expire, your app should smoothly refresh them without disrupting the merchant experience. This means implementing proper error detection and retry logic. Consider using a refresh token queue to prevent multiple simultaneous refresh attempts. Track token expiration and proactively refresh tokens before they expire.
Rate limiting affects authentication too. If you hit Shopify's API rate limits during token refresh or validation, you need fallback strategies. Implement exponential backoff for retries and maintain a token bucket system to stay within rate limits. Consider caching validated session tokens briefly to reduce API calls.
Multi-store scenarios require careful handling. Each store needs its own isolated authentication context to prevent data leaks between merchants. This includes separate token storage, session management, and API client instances. Consider using store-specific database schemas or strong isolation patterns.
Ensure auth will scale
As your app grows, authentication needs to scale too.
Session storage needs to work across multiple servers. If you're running more than one server, sessions need to be shared appropriately. Consider using Redis or similar distributed storage for session data. Implement proper session cleanup to prevent memory leaks.
Token management becomes more complex at scale. You might need to implement token rotation, manage multiple tokens per store, or handle bulk token updates. Consider building a token management service that handles rotation, expiration, and refresh centrally. Implement monitoring to track token usage and refresh patterns.
Database access patterns matter. Authentication often involves frequent reads but relatively few writes. Structure your database accordingly with appropriate indexes and caching strategies. Consider read replicas for high-traffic deployments.
Cache invalidation becomes critical. When tokens or sessions are invalidated, this needs to be reflected across all servers immediately. Implement proper cache invalidation strategies and consider using event-driven patterns for updates.
Maintaining auth over time
Authentication isn't static – it requires ongoing attention to maintain security and reliability.
Monitor for authentication failures. Set up alerts for unusual patterns like sudden increases in auth errors or failed token refreshes. Track metrics like token refresh success rates and API response times. Implement detailed logging for authentication events to aid troubleshooting.
Keep up with Shopify's changes. The platform evolves, and authentication requirements change. Stay current with Shopify's updates and deprecation notices. Subscribe to Shopify's developer changelog and plan for upcoming changes. Test your auth implementation against new API versions before they become mandatory.
Plan for upgrades carefully. When you need to make authentication changes, implement them gradually to avoid disrupting existing sessions. Consider using feature flags to roll out auth changes incrementally. Maintain backward compatibility where possible during transitions.
Shopify is moving toward more secure, standardized authentication patterns, and that means that the way apps are required to handle auth is evolving as they do. Try to stay informed about upcoming changes and plan accordingly.
If you want to avoid dealing with Shopify OAuth but you’re eager to build ecommerce apps, start with Gadget's platform that handles everything out of the box. You can join our Discord community to talk through all of your auth-related troubles with other Shopify app developers.