FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
bgschiller
bgschillerpersonalShopper
Remix of geoffreylitt/stevensDemo
Public
Like
1
personalShopper
Home
Code
10
.storybook
3
backend
4
docs
6
frontend
3
shared
1
ui-kit
12
.cursorrules
.vtignore
README.md
deno.json
Branches
1
Pull requests
Remixes
1
History
Environment variables
4
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
docs
/
oauth-setup.md
Code
/
docs
/
oauth-setup.md
Search
5/29/2025
Viewing readonly version of main branch: v214
View latest version
oauth-setup.md

Kroger OAuth Setup Guide

This guide walks you through setting up Kroger OAuth authentication for the Personal Shopper application.

Prerequisites

  1. Kroger Developer Account: You need to register as a developer with Kroger
  2. Val Town Account: Your application should be deployed on Val Town

Step 1: Register with Kroger Developer Portal

  1. Visit the Kroger Developer Portal
  2. Create an account or sign in
  3. Create a new application
  4. Note down your Client ID and Client Secret

Step 2: Configure Redirect URI

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.

Step 3: Set Environment Variables

In your Val Town environment, set these variables:

Required 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)

How to Set Environment Variables in Val Town

  1. Go to your Val Town dashboard
  2. Click on your val
  3. Go to the "Environment" tab
  4. Add the three variables listed above

Step 4: Test the OAuth Flow

  1. Visit your application URL
  2. Click "Connect with Kroger"
  3. You should be redirected to Kroger's login page
  4. After logging in and authorizing, you'll be redirected back to your app

OAuth Flow Details

1. Authorization Request

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

2. Authorization Callback

Kroger redirects back to your callback URL with:

  • code: Authorization code to exchange for tokens
  • state: The same state value you sent (for security)

3. Token Exchange

Your app exchanges the authorization code for:

  • access_token: Used to make API calls on behalf of the user
  • refresh_token: Used to get new access tokens when they expire
  • expires_in: How long the access token is valid (in seconds)

4. Profile Retrieval

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

5. User Session

The app creates a local user record and sets a session cookie for future requests.

Scopes Requested

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

Security Features

  • 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

Troubleshooting

"OAuth not configured" Error

  • Ensure all three environment variables are set correctly
  • Check that there are no extra spaces in the variable values

"Invalid redirect URI" Error

  • Verify the redirect URI in Kroger's developer portal matches exactly
  • Ensure you're using HTTPS (required by Kroger)

"Invalid client" Error

  • Double-check your client ID and secret
  • Ensure your Kroger application is active

Token Refresh Issues

  • The app automatically handles token refresh
  • If refresh fails, users will need to re-authenticate

API Endpoints

Once OAuth is configured, these endpoints become available:

Authentication

  • GET /auth/login - Start OAuth flow
  • GET /auth/callback - Handle OAuth callback
  • POST /auth/logout - End user session

User Management

  • GET /api/user - Get current user info
  • PUT /api/user/location - Update preferred store location

Data Management

  • GET /api/guidance - Get user's shopping preferences
  • POST /api/guidance - Add new preference
  • GET /api/selections - Get user's saved product selections
  • POST /api/selections - Save new product selection

Next Steps

After OAuth is working:

  1. Test the full flow with a real Kroger account
  2. Implement product search using the Kroger Products API
  3. Add cart management using the Kroger Cart API
  4. Integrate AI/LLM for intelligent product selection
  5. Build the shopping list interface

Support

For Kroger API issues:

  • Kroger Developer Documentation
  • Kroger Developer Support

For Val Town issues:

  • Val Town Documentation
  • Val Town Discord
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
Ā© 2025 Val Town, Inc.