Authenticate to a GitHub MCP server with Token Vault and Okta

TL;DR

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

If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. 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.
  2. Set the personal access token as an environment variable:

    export KONNECT_TOKEN='YOUR KONNECT TOKEN'

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.

You must enable Token Vault on your Kong Identity directory. Enable it, or check if it’s already enabled.

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.

  1. 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
  2. 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')
  3. 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)
  4. 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")

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.

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.

  1. 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
  2. Create a custom authorization server with http://localhost:8000/github as its audience, and an access policy that assigns it to the application.

  3. 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'

Create an OAuth app in GitHub.

  1. Set the following values for demo purposes:

    • Homepage URL: https://cloud.konghq.com
    • Authorization callback URL: http://localhost:8000/_vault/callback
  2. Export its client ID and secret:

    export GITHUB_CLIENT_ID='YOUR_GITHUB_CLIENT_ID'
    export GITHUB_CLIENT_SECRET='YOUR_GITHUB_CLIENT_SECRET'
  1. Install Claude Code:
     curl -fsSL https://claude.ai/install.sh | bash
  2. 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_enabled lets users who sign in through Okta use the Token Vault.
  • jit_provisioning_enabled creates 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: github uses Token Vault’s built-in GitHub OAuth settings, so you don’t configure GitHub’s authorization and token URLs.
  • client_id and client_secret identify the GitHub OAuth app that you created in the prerequisites.
  • scopes are the GitHub permissions that users grant. repo lets the agent read and write repositories, and read:user lets it read profile information.
  • credential_type: user stores 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"
       }
     }'
  • issuer and client_id point to your Okta authorization server and the native application that signs users in.
  • auth_methods accepts the Okta access token as a bearer token.
  • cache_tokens_salt is required for openid-connect AI 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.url and config.route.paths set the upstream GitHub MCP server and the /github path that the gateway exposes it on.
  • datastores and token_vault.provider tell the gateway which data store and provider to use when it looks up the user’s GitHub token in the Token Vault.
  • access.auth_strategies references the okta-oidc AI Auth Strategy.
  • access.acl_attribute_type and access.access_token_claim_field identify the caller by the sub claim of their Okta access token.
  • access.metadata advertises 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

  1. Add the MCP server:

    claude mcp add --transport http \
      --client-id "$OKTA_CLIENT_ID" \
      --callback-port 61337 \
      github-vault-demo "http://localhost:8000/github"
  2. Start a Claude Code session, run /mcp, and select github-vault-demo to sign in with Okta.

Validate the setup

  1. In your Claude Code session, run /mcp and select github-vault-demo to list the server’s tools. Before enrollment, the server only returns the authenticate tool.

  2. Ask Claude Code to call authenticate, then open the returned URL and approve GitHub’s consent screen.

  3. After enrollment, github-vault-demo appears connected and displays the available tools.

Cleanup

To clean up all AI Gateway resources created in this guide, run:

curl -Ls https://get.konghq.com/ai | bash -s -- -d

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.pem

FAQs

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.

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 openid and offline_access scopes, which Claude Code requests.
  • Make sure the client_id in the authorization request matches $OKTA_CLIENT_ID. Claude Code saves the client ID from when you first ran claude mcp add, so if you registered the server with a different ID, run claude mcp remove github-vault-demo and add it again with the correct --client-id.
  • Make sure the application’s sign-in redirect URI is exactly http://localhost:61337/callback.

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.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!