|
| 1 | +--- |
| 2 | +title: Setting up Okta as an Authentication Server for MCP OAuth Authentication |
| 3 | +--- |
| 4 | + |
| 5 | +In this guide, you'll learn how to configure Okta as an authorization server |
| 6 | +for use with the MCP Server handler. See the |
| 7 | +[MCP Server Handler docs](../handlers/mcp-server.md#oauth-authentication) for |
| 8 | +instructions on how to configure your Zuplo gateway to support OAuth |
| 9 | +authentication for your MCP Server. |
| 10 | + |
| 11 | +This guide will assume that you already have a working Okta account and organization. |
| 12 | + |
| 13 | +## Create an Auth Server |
| 14 | + |
| 15 | +First, you will need to create an Okta authorization server. |
| 16 | +This server will be used to authorize requests to your MCP Server per |
| 17 | +[the Model Context Protocol authorization specification.](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization) |
| 18 | + |
| 19 | +1. In the Okta Admin Console, navigate to **Security > API** in the left sidebar. |
| 20 | +2. Click **Add Authorization Server**. |
| 21 | +3. Set the **Name** to something like "MCP Server Authorization". |
| 22 | +4. Set the **Audience** to the canonical URL of your MCP Server. For example, if your MCP Server is hosted |
| 23 | + at `https://my-gateway.zuplo.dev/mcp`, then the audience would be |
| 24 | + `https://my-gateway.zuplo.dev/mcp`. **The trailing slash is not required.** |
| 25 | +5. Add a **Description** and click **Save**. |
| 26 | + |
| 27 | +Note the **Issuer Metadata URI** shown in the authorization server details. |
| 28 | +You'll need this for your Zuplo configuration. |
| 29 | + |
| 30 | +## Configure Scopes |
| 31 | + |
| 32 | +Next, you'll need to configure the scopes for your authorization server. |
| 33 | + |
| 34 | +1. In your authorization server settings, click the **Scopes** tab. |
| 35 | +2. Click **Add Scope**. |
| 36 | +3. Set the **Name** to something like `mcp:access`. |
| 37 | +4. Add a **Display phrase** and **Description** (like "Access to MCP Server tools"). |
| 38 | +5. Check **Set as a default scope** and click **Create**. |
| 39 | + |
| 40 | +## Create an OAuth Client Application |
| 41 | + |
| 42 | +Next, you'll need to create an OAuth client application for your MCP server. |
| 43 | + |
| 44 | +:::note |
| 45 | + |
| 46 | +Okta requires an admin API key for to dynamically register clients. |
| 47 | +This may not be well supported by MCP clients. |
| 48 | +However, MCP clients should also support an alternative way to obtain a client ID and client credential. |
| 49 | +This document assumes an MCP client can set these fields without having to dynamically register a client. |
| 50 | + |
| 51 | +::: |
| 52 | + |
| 53 | +1. In the Okta Admin Console, navigate to **Applications > Applications** in the left sidebar. |
| 54 | +2. Click **Create App Integration**. |
| 55 | +3. Select **OIDC - OpenID Connect** as the sign-in method. |
| 56 | +4. Select **Web Application** as the application type and click **Next**. |
| 57 | +5. Set the **App integration name** to something like "MCP Client Application". |
| 58 | +6. For **Grant types**, check **Authorization Code** and **Refresh Token**. |
| 59 | +7. For **Sign-in redirect URIs**, leave this empty or set to a placeholder like `http://localhost:3000/callback`. |
| 60 | +8. For **Controlled access**, select **Allow everyone in your organization to access**. |
| 61 | +9. Click **Save**. |
| 62 | + |
| 63 | +After creating the application, note the **Client ID** and **Client Secret** |
| 64 | +from the application's **General** tab. You'll need these for your MCP client configuration. |
| 65 | + |
| 66 | +## Create a Default Policy and Rule |
| 67 | + |
| 68 | +You'll need to create an access policy for your authorization server. |
| 69 | + |
| 70 | +1. In your authorization server settings (found in **Security > API**) click the **Access Policies** tab. |
| 71 | +2. Click **Add New Access Policy**. |
| 72 | +3. Set the **Name** to something like "MCP Client Access Policy". |
| 73 | +4. Add a **Description** and assign it to **All clients**. |
| 74 | +5. Click **Create Policy**. |
| 75 | + |
| 76 | +Now create a rule for this policy: |
| 77 | + |
| 78 | +1. Click **Add Rule** within your new policy. |
| 79 | +2. Set the **Rule Name** to something like "Allow MCP Access". |
| 80 | +3. In the **IF AND** section: |
| 81 | + - **Grant type is**: Select the grant type. For the widest grant for all MCP clients, select **Client Credentials**, **Authorization Code**, and **Device Authorization** (???) |
| 82 | + - **User is**: Select **Any user assigned the app** |
| 83 | + - **Scopes requested**: Select **The following scopes** and choose the scope you created for the authorization server (i.e., `mcp:access`) |
| 84 | +4. In the **THEN AND** section: |
| 85 | + - **Use this inline hook**: None (disabled) |
| 86 | + - **Access token lifetime is**: Set to desired value (e.g., 1 hour) |
| 87 | + - **Refresh token lifetime is**: Set to desired value (e.g., 90 days) |
| 88 | +5. Click **Create Rule**. |
| 89 | + |
| 90 | +## Configure OAuth on Zuplo |
| 91 | + |
| 92 | +To set up your gateway to support OAuth authentication for your MCP Server, you |
| 93 | +will need to do the following: |
| 94 | + |
| 95 | +1. Create an Okta JWT Auth inbound policy on your MCP Server route. This policy will need to |
| 96 | + have the option `"oAuthResourceMetadataEnabled": true` to enable authorization resource metadata discovery. |
| 97 | + |
| 98 | + ```json |
| 99 | + { |
| 100 | + "name": "mcp-okta-oauth-inbound", |
| 101 | + "policyType": "okta-jwt-auth-inbound", |
| 102 | + "handler": { |
| 103 | + "export": "OktaJwtInboundPolicy", |
| 104 | + "module": "$import(@zuplo/runtime)", |
| 105 | + "options": { |
| 106 | + "oAuthResourceMetadataEnabled": true, |
| 107 | + "audience": "https://my-gateway.zuplo.dev/mcp", |
| 108 | + "issuer": "https://your-okta-domain.okta.com/oauth2/your-auth-server-id", |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + ``` |
| 113 | + |
| 114 | + * Replace `my-gateway.zuplo.dev/mcp` with the audience you defined in your authorization server. |
| 115 | + * Replace `your-okta-domain` in the `issuer` field with your actual Okta domain. |
| 116 | + * Replace `your-auth-server-id` in the `issuer` field with the actual ID of your Okta authorization server. |
| 117 | + |
| 118 | +2. Add the OAuth policy to the MCP Server route. For example: |
| 119 | + |
| 120 | + ```json |
| 121 | + "paths": { |
| 122 | + "/mcp": { |
| 123 | + "post": { |
| 124 | + "x-zuplo-route": { |
| 125 | + |
| 126 | + // etc. etc. |
| 127 | + // other properties for the MCP server route handler |
| 128 | + |
| 129 | + "policies": { |
| 130 | + "inbound": [ |
| 131 | + "mcp-oauth-inbound" |
| 132 | + ] |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + ``` |
| 139 | + |
| 140 | +3. Add the `OAuthProtectedResourcePlugin` to your `runtimeInit` function in the |
| 141 | + `modules/zuplo.runtime.ts` file: |
| 142 | + |
| 143 | + ```ts |
| 144 | + import { |
| 145 | + RuntimeExtensions, |
| 146 | + OAuthProtectedResourcePlugin, |
| 147 | + } from "@zuplo/runtime"; |
| 148 | + |
| 149 | + export function runtimeInit(runtime: RuntimeExtensions) { |
| 150 | + runtime.addPlugin( |
| 151 | + new OAuthProtectedResourcePlugin({ |
| 152 | + authorizationServers: [ "https://your-okta-domain.okta.com/oauth2/your-auth-server-id" ], |
| 153 | + resourceName: "My MCP OAuth Resource", |
| 154 | + }), |
| 155 | + ); |
| 156 | + } |
| 157 | + ``` |
| 158 | + |
| 159 | + * Replace `your-okta-domain` in the `issuer` field with your actual Okta domain. |
| 160 | + * Replace `your-auth-server-id` in the `issuer` field with the actual ID of your Okta authorization server. |
| 161 | + |
| 162 | + This plugin populates the `.well-known` routes for the MCP server auth metadata discover. |
| 163 | + This enables MCP clients to automatically discover the authorization issuer endpoint. |
| 164 | + See the |
| 165 | + [OAuth Protected Resource Plugin docs](../programmable-api/oauth-protected-resource-plugin) |
| 166 | + for more details on this runtime plugin. |
| 167 | + |
| 168 | +## Testing |
| 169 | + |
| 170 | +The [MCP Inspector](https://github.com/modelcontextprotocol/inspector) |
| 171 | +doesn't currently support setting an initial access token or presenting a UI for |
| 172 | +setting the client ID or secret. |
| 173 | + |
| 174 | +Refer to the [Manual OAuth MCP Testing](./manual-mcp-oauth-testing) guide for |
| 175 | +further instructions on testing your MCP server with `curl`. |
| 176 | + |
| 177 | +If you need more help debugging, see |
| 178 | +[Testing OAuth on Zuplo](../handlers/mcp-server.md#oauth-testing). |
0 commit comments