mirror of
https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
synced 2025-09-08 20:50:46 +00:00
4.0 KiB
4.0 KiB
Okta OpenID Connect PKCE Setup Guide
📋 Navigation
🏠 README | 📖 Setup Guide | 🏗️ Architecture | 🔧 Scripts | 🤖 Client | ⚙️ Config | 🔐 Okta Setup
Overview
This guide sets up Okta PKCE authentication for Bedrock AgentCore Gateway using the existing iframe-oauth-flow.html
- a complete, self-contained PKCE application.
Prerequisites
- Okta Developer Account (free at developer.okta.com)
- Access to Bedrock AgentCore Gateway (beta access required)
- nginx installed locally
Okta Setup
Create an OIDC Application
- Log in to your Okta Developer Console
- Navigate to Applications → Applications → Create App Integration
- Configure:
App name: bedrock-agentcore-gateway-client Grant types: ✅ Authorization Code, ✅ Refresh Token Sign-in redirect URIs: http://localhost:8080/okta-auth/ Allowed grant types: ✅ Authorization Code Client authentication: ✅ Use PKCE (for public clients)
- Save the application
Configure API Scopes
- Security → API → Authorization Servers → default
- Ensure scopes exist:
openid
,profile
,email
- Add custom scopes if needed:
bedrock-agentcore:read
,bedrock-agentcore:write
Local Setup
Configure Local nginx
# Navigate to the project directory
cd /path/to/project
# Start with provided configuration
sudo nginx -c $(pwd)/okta-auth/nginx/okta-local.conf
Configure OAuth Parameters
- Open
iframe-oauth-flow.html
in a text editor - Update the configuration section (around line 50):
const config = { clientId: 'YOUR_CLIENT_ID', redirectUri: 'http://localhost:8080/okta-auth/', authorizationEndpoint: 'https://dev-12345678.okta.com/oauth2/default/v1/authorize', tokenEndpoint: 'https://dev-12345678.okta.com/oauth2/default/v1/token', scope: 'openid profile email', };
- Replace with your values:
- Client ID: From your Okta application
- Okta Domain: Your Okta domain (e.g.,
dev-12345678.okta.com
) - Auth Server ID:
default
Note: The iframe file handles all PKCE logic, token management, and Bedrock AgentCore Gateway integration automatically.
Test the Setup
- Open a browser and navigate to: http://localhost:8080/okta-auth/
- Click "Login with Okta"
- Complete the Okta authentication flow
- You should see the access token displayed on the page
- Copy this token for use with the client application
Using the Token
# Copy the token to the client's token file
echo "YOUR_ACCESS_TOKEN" > ../client/token.txt
# Run the client with the token
cd ../client
python aws_operations_agent_mcp.py
Troubleshooting
Common Issues
-
CORS Errors:
- Ensure your Okta application has the correct redirect URI
- Check that nginx is running with the provided configuration
-
Invalid Client Error:
- Verify your Client ID is correct
- Ensure PKCE is enabled for the application
-
Token Not Working:
- Check token expiration (default is 1 hour)
- Verify scopes match what's required by the gateway
Debugging
# Check nginx configuration
nginx -t -c /path/to/okta-local.conf
# View nginx logs
tail -f /usr/local/var/log/nginx/error.log
# Test token with curl
curl -H "Authorization: Bearer YOUR_TOKEN" https://your-gateway-url/mcp
Advanced Configuration
The iframe-oauth-flow.html
file is a complete PKCE implementation that includes:
- Code challenge and verifier generation
- Authorization code flow
- Token exchange and refresh
- Complete PKCE implementation (lines 330+)
- Token display and management
- Bedrock AgentCore Gateway integration
- All necessary HTML, CSS, and JavaScript
You can customize this file for your specific needs or use it as a reference for implementing PKCE in your own applications.