DIRECTORY_ID=$(curl -X POST "https://us.api.konghq.com/v2/directories" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/json" \
--json '{
"name": "kong-identity-directory",
"description": "Directory for this tutorial",
"allow_all_control_planes": true
}' | jq -r ".id"
)Authenticate to a GitHub MCP server with Token Vault and Okta
Allow an AI agent such as Claude Code call the GitHub MCP server on a user’s behalf, with the user signing in through Okta and Kong storing their GitHub token in Token Vault, so the agent never handles a GitHub credential..
Prerequisites
Kong Konnect
If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
- The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Set the personal access token as an environment variable:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Kong Identity directory
A directory is a regional collection of principals. A Konnect organization supports only one Kong Identity directory. Create a directory for the tutorial, or look up your existing one.
Kong Identity Token Vault
You must enable Token Vault on your Kong Identity directory. Enable it, or check if it’s already enabled.
Vault encryption key
Token Vault encrypts every credential it stores with a public key that you register. The matching private key stays on the AI Gateway data plane, so Kong Identity can’t decrypt your users’ credentials.
-
Generate an EC P-256 key pair:
openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out vault-private.pem openssl pkey -in vault-private.pem -pubout -out vault-public.pem -
Export the private key as a single line, so the data plane can read it when it starts:
export TOKEN_VAULT_PRIVATE_KEY=$(grep -v -- '-----' vault-private.pem | tr -d '\n') -
Export the public key, with the newlines escaped so it fits in a JSON body:
export VAULT_PUBLIC_KEY=$(awk 'NF {printf "%s\\n", $0}' vault-public.pem) -
Register the public key as a vault key:
_response=$(curl -X POST "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/vault/keys" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/json" \
--json '{
"name": "my-vault-key",
"public_key": "'$VAULT_PUBLIC_KEY'"
}')Export the env variables:
export VAULT_KEY_ID=$(echo "$_response" | jq -r ".id")
export VAULT_KEY_KID=$(echo "$_response" | jq -r ".kid")AI Gateway running
Run the AI Gateway quickstart script to automatically provision a control plane and data plane in Kong Konnect, and configure your environment:
curl -Ls https://get.konghq.com/ai | bash -s -- -k $KONNECT_TOKEN \
-e TOKEN_VAULT_PRIVATE_KEY!–vale on–>
This sets up a AI Gateway control plane named ai-quickstart, provisions a local data plane, and prints out the following environment variables export:
export AI_GATEWAY_ID=your-gateway-id
export KONNECT_TOKEN=$KONNECT_TOKEN
export KONNECT_CONTROL_PLANE_NAME=ai-quickstart
export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
export KONNECT_PROXY_URL='http://localhost:8000'Copy and paste these into your terminal to configure your session.
Want a fully-hosted AI Gateway? See AI Gateway 2.0 on Dedicated Cloud Gateways.
Okta as the user IdP
You need admin access to an Okta org, with a custom authorization server and a native OIDC application that the agent uses to sign users in. This guide needs a custom authorization server because Token Vault only accepts JWT access tokens, and the tokens that the Okta org authorization server issues aren’t meant to be validated by third parties.
-
Create a native OIDC application with the Authorization Code and Refresh Token grant types, and the following sign-in redirect URI:
http://localhost:61337/callback -
Create a custom authorization server with
http://localhost:8000/githubas its audience, and an access policy that assigns it to the application. -
Export the application’s client ID and the authorization server’s issuer URI:
export OKTA_CLIENT_ID='YOUR_OKTA_CLIENT_ID' export OKTA_ISSUER='https://YOUR_OKTA_DOMAIN/oauth2/YOUR_AUTH_SERVER_ID'
GitHub OAuth app
Create an OAuth app in GitHub.
-
Set the following values for demo purposes:
- Homepage URL:
https://cloud.konghq.com - Authorization callback URL:
http://localhost:8000/_vault/callback
- Homepage URL:
-
Export its client ID and secret:
export GITHUB_CLIENT_ID='YOUR_GITHUB_CLIENT_ID' export GITHUB_CLIENT_SECRET='YOUR_GITHUB_CLIENT_SECRET'
AI agent
- Install Claude Code:
curl -fsSL https://claude.ai/install.sh | bash - Verify the installation:
claude --version
Trust Okta as the identity provider
Tell your Kong Identity directory to trust tokens that your Okta authorization server issues. For this, send a POST request to the directory’s trusted-idps endpoint with the issuer URL of your Okta authorization server:
TRUSTED_IDP_ID=$(curl -X POST "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/trusted-idps" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"issuer_url": "'$OKTA_ISSUER'",
"display_name": "Okta",
"vault_access_enabled": true,
"jit_provisioning_enabled": true
}' | jq -r ".id"
)vault_access_enabledlets users who sign in through Okta use the Token Vault.jit_provisioning_enabledcreates a user in the directory the first time someone signs in.
Create the GitHub provider
Create a GitHub provider in the directory’s Token Vault by sending a POST request to the vault/providers endpoint with the github provider template and your GitHub OAuth app’s client ID and secret.
The provider:
- Enables Token Vault to run GitHub’s OAuth flow on behalf of each user.
- Defines which permissions to request.
PROVIDER_ID=$(curl -X POST "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/vault/providers" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"template_name": "github",
"name": "github",
"client_id": "'$GITHUB_CLIENT_ID'",
"client_secret": "'$GITHUB_CLIENT_SECRET'",
"scopes": [
"repo",
"read:user"
],
"credential_type": "user"
}' | jq -r ".id"
)template_name: githubuses Token Vault’s built-in GitHub OAuth settings, so you don’t configure GitHub’s authorization and token URLs.client_idandclient_secretidentify the GitHub OAuth app that you created in the prerequisites.scopesare the GitHub permissions that users grant.repolets the agent read and write repositories, andread:userlets it read profile information.credential_type: userstores one token per user rather than one shared token.
Create a Token Vault data store
Create a data store that tells AI Gateway how to connect to Token Vault. The gateway needs it to retrieve the GitHub tokens that you store in Token Vault:
curl -X POST "https://us.api.konghq.com/v1/ai-gateways/$AI_GATEWAY_ID/datastores" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/json" \
--json '{
"name": "token-vault-datastore",
"display_name": "Token Vault data store",
"type": "token-vault",
"config": {
"directory": "'$DIRECTORY_NAME'",
"current_version": "'$VAULT_KEY_KID'",
"keys": [
{
"version": "'$VAULT_KEY_KID'",
"key": "{vault://env/TOKEN_VAULT_PRIVATE_KEY}"
}
]
}
}'Create an AI Auth Strategy for Okta
Create an openid-connect AI Auth Strategy so the gateway can validate the Okta access tokens that users present when they call the GitHub MCP server:
curl -X POST "https://us.api.konghq.com/v1/ai-gateways/$AI_GATEWAY_ID/auth-strategies" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/json" \
--json '{
"name": "okta-oidc",
"display_name": "Okta OIDC",
"type": "openid-connect",
"config": {
"issuer": "'$OKTA_ISSUER'",
"client_id": [
"'$OKTA_CLIENT_ID'"
],
"auth_methods": [
"bearer"
],
"scopes": [
"openid",
"offline_access"
],
"cache_tokens_salt": "okta-oidc-cache-salt"
}
}'issuerandclient_idpoint to your Okta authorization server and the native application that signs users in.auth_methodsaccepts the Okta access token as a bearer token.cache_tokens_saltis required foropenid-connectAI Auth Strategies. Set it to any unique string, which the gateway uses to build the cache key for token endpoint requests.
Create the AI MCP Server
Create an AI MCP Server in passthrough-listener mode, which proxies MCP traffic to the GitHub MCP server without converting its tools. The server uses:
- The Okta AI Auth Strategy to authenticate users.
- The Token Vault data store and GitHub provider to get each user’s GitHub token.
Send the following request to create the AI MCP Server:
curl -X POST "https://us.api.konghq.com/v1/ai-gateways/$AI_GATEWAY_ID/mcp-servers" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/json" \
--json '{
"name": "github",
"display_name": "GitHub",
"type": "passthrough-listener",
"enabled": true,
"config": {
"url": "https://api.githubcopilot.com/mcp/",
"route": {
"paths": [
"/github"
]
}
},
"datastores": [
{
"name": "token-vault-datastore"
}
],
"token_vault": {
"provider": "github"
},
"access": {
"acl_attribute_type": "oauth_access_token",
"access_token_claim_field": ".sub",
"auth_strategies": [
"okta-oidc"
],
"metadata": {
"resource": "http://localhost:8000/github",
"authorization_servers": [
"'$OKTA_ISSUER'"
],
"scopes_supported": [
"openid",
"offline_access"
]
}
}
}'config.urlandconfig.route.pathsset the upstream GitHub MCP server and the/githubpath that the gateway exposes it on.datastoresandtoken_vault.providertell the gateway which data store and provider to use when it looks up the user’s GitHub token in the Token Vault.access.auth_strategiesreferences theokta-oidcAI Auth Strategy.access.acl_attribute_typeandaccess.access_token_claim_fieldidentify the caller by thesubclaim of their Okta access token.access.metadataadvertises Okta as the authorization server, so that Claude Code knows where to send users to sign in.
Connect Claude Code to the AI MCP Server
-
Add the MCP server:
claude mcp add --transport http \ --client-id "$OKTA_CLIENT_ID" \ --callback-port 61337 \ github-vault-demo "http://localhost:8000/github" -
Start a Claude Code session, run
/mcp, and selectgithub-vault-demoto sign in with Okta.
Validate the setup
-
In your Claude Code session, run
/mcpand selectgithub-vault-demoto list the server’s tools. Before enrollment, the server only returns theauthenticatetool. -
Ask Claude Code to call
authenticate, then open the returned URL and approve GitHub’s consent screen. -
After enrollment,
github-vault-demoappears connected and displays the available tools.
Cleanup
Clean up AI Gateway resources
To clean up all AI Gateway resources created in this guide, run:
curl -Ls https://get.konghq.com/ai | bash -s -- -dClean up Kong Identity resources
Delete the GitHub provider, the trusted IdP, and the vault key from your directory:
curl -X DELETE "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/vault/providers/$PROVIDER_ID" \
-H "Authorization: Bearer $KONNECT_TOKEN"
curl -X DELETE "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/trusted-idps/$TRUSTED_IDP_ID" \
-H "Authorization: Bearer $KONNECT_TOKEN"
curl -X DELETE "https://us.api.konghq.com/v2/directories/$DIRECTORY_ID/vault/keys/$VAULT_KEY_ID" \
-H "Authorization: Bearer $KONNECT_TOKEN"
rm vault-private.pem vault-public.pemFAQs
Why does claude mcp login send me to http://localhost:8000/authorize and return no Route matched?
The claude mcp login command doesn’t use the authorization server that the AI MCP Server advertises in its protected resource metadata. It sends you to http://localhost:8000/authorize, which the data plane doesn’t serve.
Sign in from a Claude Code session instead. Run /mcp and select the server, and Claude Code redirects you to Okta.
Why does Okta return a 400 error when Claude Code redirects me to sign in?
Okta returns a 400 error on the authorization request when the authorization server’s access policy doesn’t apply correctly to the native application that Claude Code uses. Check the following:
- Assign the access policy only to the native application that you created for this guide, not to all clients. Add a rule to the policy that allows the Authorization Code and Refresh Token grant types, and the
openidandoffline_accessscopes, which Claude Code requests. - Make sure the
client_idin the authorization request matches$OKTA_CLIENT_ID. Claude Code saves the client ID from when you first ranclaude mcp add, so if you registered the server with a different ID, runclaude mcp remove github-vault-demoand add it again with the correct--client-id. - Make sure the application’s sign-in redirect URI is exactly
http://localhost:61337/callback.
Why does Claude Code sign me in to Okta without showing a consent screen?
Okta only shows a consent screen when the authorization server’s access policy requires it. Without that setting, Okta redirects you back to Claude Code without asking you to approve anything, and Claude Code reports that authentication succeeded.
To show the consent screen, edit the access policy rule that applies to the native application and configure it to require user consent.