This guide walks you through setting up Kroger OAuth authentication for the Personal Shopper application.
- Kroger Developer Account: You need to register as a developer with Kroger
- Val Town Account: Your application should be deployed on Val Town
- Visit the Kroger Developer Portal
- Create an account or sign in
- Create a new application
- Note down your
Client ID
andClient Secret
In your Kroger application settings, set the redirect URI to:
https://your-val-name.web.val.run/auth/callback
Replace your-val-name
with your actual Val Town username and val name.
In your Val Town environment, set these variables:
- KROGER_CLIENT_ID: Your Kroger application's client ID
- KROGER_CLIENT_SECRET: Your Kroger application's client secret
- KROGER_REDIRECT_URI: The redirect URI you registered (e.g.,
https://your-val-name.web.val.run/auth/callback
)
- Go to your Val Town dashboard
- Click on your val
- Go to the "Environment" tab
- Add the three variables listed above
- Visit your application URL
- Click "Connect with Kroger"
- You should be redirected to Kroger's login page
- After logging in and authorizing, you'll be redirected back to your app
When a user clicks "Connect with Kroger", they're redirected to:
https://api.kroger.com/v1/connect/oauth2/authorize?
client_id=YOUR_CLIENT_ID&
redirect_uri=YOUR_REDIRECT_URI&
response_type=code&
scope=profile.compact cart.basic:write product.compact&
state=RANDOM_STATE_STRING
Kroger redirects back to your callback URL with:
code
: Authorization code to exchange for tokensstate
: The same state value you sent (for security)
Your app exchanges the authorization code for:
access_token
: Used to make API calls on behalf of the userrefresh_token
: Used to get new access tokens when they expireexpires_in
: How long the access token is valid (in seconds)
Your app uses the access token to get the user's Kroger profile ID from:
GET https://api.kroger.com/v1/identity/profile
Authorization: Bearer ACCESS_TOKEN
The app creates a local user record and sets a session cookie for future requests.
The application requests these OAuth scopes:
- profile.compact: Access to user's basic profile information
- cart.basic:write: Ability to add items to the user's cart
- product.compact: Access to search products in the catalog
- State Parameter: Prevents CSRF attacks during OAuth flow
- HTTP-Only Cookies: Session cookies are not accessible via JavaScript
- Token Refresh: Automatic refresh of expired access tokens
- Secure Storage: Tokens are stored securely in the database
- Ensure all three environment variables are set correctly
- Check that there are no extra spaces in the variable values
- Verify the redirect URI in Kroger's developer portal matches exactly
- Ensure you're using HTTPS (required by Kroger)
- Double-check your client ID and secret
- Ensure your Kroger application is active
- The app automatically handles token refresh
- If refresh fails, users will need to re-authenticate
Once OAuth is configured, these endpoints become available:
GET /auth/login
- Start OAuth flowGET /auth/callback
- Handle OAuth callbackPOST /auth/logout
- End user session
GET /api/user
- Get current user infoPUT /api/user/location
- Update preferred store location
GET /api/guidance
- Get user's shopping preferencesPOST /api/guidance
- Add new preferenceGET /api/selections
- Get user's saved product selectionsPOST /api/selections
- Save new product selection
After OAuth is working:
- Test the full flow with a real Kroger account
- Implement product search using the Kroger Products API
- Add cart management using the Kroger Cart API
- Integrate AI/LLM for intelligent product selection
- Build the shopping list interface
For Kroger API issues:
For Val Town issues: