| title | description |
|---|---|
Complete Setup Guide |
Step-by-step setup guide for all environments |
This guide will walk you through setting up the Auth Integration API documentation for development, staging, and production environments.
git clone <your-repo>
cd auth_integration
npm install# Copy example environment file
cp env.example .env.local
# Edit with your actual development credentials
nano .env.local# Option 1: Use the convenience script (recommended)
./start-dev.sh
# Option 2: Use npm directly
npm run dev- Open
http://localhost:4321 - Click "Cognito Test" in the sidebar
- Test your AWS Cognito integration
- Node.js 18+ installed
- AWS Cognito user pool configured
- Git for version control
- Text editor (VS Code recommended)
git clone <your-repo-url>
cd auth_integrationnpm installnpm run dev
# Should start server at http://localhost:4321Create .env.local file (excluded from version control):
# .env.local
NODE_ENV=development
COGNITO_DOMAIN=your-dev-cognito-domain.auth.region.amazoncognito.com
COGNITO_CLIENT_ID=your_dev_client_id
COGNITO_CLIENT_SECRET=your_dev_client_secret
COGNITO_SCOPE=cognito-api-scope
API_BASE_URL=http://localhost:3000/v1Create .env.staging.local file (excluded from version control):
# .env.staging.local
NODE_ENV=staging
COGNITO_DOMAIN=your-staging-cognito-domain.auth.region.amazoncognito.com
COGNITO_CLIENT_ID=your_staging_client_id
COGNITO_CLIENT_SECRET=your_staging_client_secret
COGNITO_SCOPE=cognito-api-scope
API_BASE_URL=https://staging-api.example.com/v1Configure environment variables in your hosting platform:
# Production Environment Variables
NODE_ENV=production
COGNITO_DOMAIN=your-prod-cognito-domain.auth.region.amazoncognito.com
COGNITO_CLIENT_ID=your_prod_client_id
COGNITO_CLIENT_SECRET=your_prod_client_secret
COGNITO_SCOPE=cognito-api-scope
API_BASE_URL=https://api.example.com/v1- Go to AWS Cognito Console
- Create a new User Pool
- Configure authentication settings
- Create an App Client
- Note down the Client ID and Client Secret
- Enable OAuth2 flows
- Add your domain to allowed origins
- Configure scopes
- Set up redirect URLs
# Test with cURL
curl -X POST "https://YOUR_COGNITO_DOMAIN/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=cognito-api-scope"# Option 1: Use the convenience script (recommended)
./start-dev.sh
# Option 2: Use npm directly
npm run dev
# Test in browser
open http://localhost:4321/cognito-test# Start staging server
npm run dev:staging
# Test in browser
open http://localhost:4321/cognito-test# Start production server
npm run dev:prod
# Test in browser
open http://localhost:4321/cognito-test# Development build
npm run build
# Staging build
npm run build:staging
# Production build
npm run build:prod- Push your code to a GitHub repository
- Enable GitHub Pages in repository settings
- Select "GitHub Actions" as the source
- Configuration is already set up for
casparhealthorganization - Push to
mainbranch for automatic deployment
Your site will be available at: https://casparhealth.github.io/auth-integration
# Build the project
npm run build:prod
# Upload dist/ folder to your hosting provider- Never commit
.env*files to git - Always use environment variables for production
- Rotate secrets regularly
- Use different credentials for each environment
The .gitignore file automatically protects against secret commits:
# Environment variables (KEEP LOCAL - NEVER COMMIT)
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.env.staging.local- Development: Use
.env.localfile - Staging: Use
.env.staging.localfile - Production: Use hosting platform environment variables
Visit the API Reference page to view the complete API specification:
- Review the OAuth2 token endpoint documentation
- Check the request/response schemas
- Use the provided code examples
- Go to
http://localhost:4321 - Click "Cognito Test" in the sidebar
- Follow the examples provided
- Go to
http://localhost:4321/api - View the complete API specification
- Use the provided code examples
- Check your
client_idandclient_secret - Verify they match your Cognito App Client
- Ensure the App Client is properly configured
- Add your domain to Cognito allowed origins
- Check if you're using the correct Cognito domain
- Verify HTTPS is used for production
- Check if
.env.localfile exists - Verify the file is in the project root
- Restart the development server
- Check if all dependencies are installed
- Verify Node.js version (18+ required)
- Check for syntax errors in configuration files
-
Check Environment Variables
# Print current environment echo $NODE_ENV # Check if .env.local exists ls -la .env*
-
Verify Cognito Configuration
# Test Cognito endpoint directly curl -X POST "https://YOUR_COGNITO_DOMAIN/oauth2/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id=YOUR_CLIENT_ID" \ -d "client_secret=YOUR_CLIENT_SECRET" \ -d "scope=cognito-api-scope"
-
Check Server Logs
# Start with verbose logging npm run dev -- --verbose
- Edit
openapi.yamlto add more endpoints - Update
src/content/docs/for custom pages - Modify
astro.config.mjsfor configuration
- Implement authentication middleware
- Add more API endpoints
- Create custom components
- Set up CI/CD pipeline
- Configure monitoring
- Set up backups
- Check the Security Guide for credential management
- Visit the Cognito Test page for testing examples
- Review the API Reference for detailed endpoint documentation
- Check the console for any error messages
Ready to get started? Follow the Quick Start guide above to get up and running in 5 minutes!