Skip to content

Commit 36218c9

Browse files
Added token exchange signer (#5)
* Added token exchange signer Signed-off-by: Richard Gebhardt <[email protected]> Co-authored-by: Richard Gebhardt <[email protected]>
1 parent abd5852 commit 36218c9

File tree

10 files changed

+362
-352
lines changed

10 files changed

+362
-352
lines changed

server/IAMConfig.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## IAM Domain Configuration Steps
2+
3+
### Make sure client access is enabled for JWK's URL
4+
5+
1. Login to OCI console (https://cloud.oracle.com for OCI commercial cloud).
6+
2. From "Identity & Security" menu, open Domains page.
7+
3. On the Domains list page, select the domain that you are using for MCP Authentication.
8+
4. Open Settings tab.
9+
5. Click on "Edit Domain Settings" button.
10+
11+
![Edit IAM Domain Settings](./ocieditdomainsettingsbutton.png)
12+
13+
6. Enable "Configure client access" checkbox as show in the screenshot.
14+
15+
![IAM Domain Settings](./ocieditdomainsettings.png)
16+
17+
### Create OAuth client for MCP server authentication
18+
19+
1. Login to OCI console (https://cloud.oracle.com for OCI commercial cloud).
20+
2. From "Identity & Security" menu, open Domains page.
21+
3. On the Domains list page, select the domain in which you want to create MCP server OAuth client. If you need help finding the list page for the domain, see [Listing Identity Domains.](https://docs.oracle.com/en-us/iaas/Content/Identity/domains/to-view-identity-domains.htm#view-identity-domains).
22+
4. On the details page, select Integrated applications. A list of applications in the domain is displayed.
23+
5. Select Add application.
24+
6. In the Add application window, select Confidential Application.
25+
7. Select Launch workflow.
26+
8. In the Add application details page, Enter name and description as shown below.
27+
28+
![Add Confidential Integrated Application](./ociaddapplication.png)
29+
30+
9. Once the Integrated Application is created, Click on "OAuth configuration" tab.
31+
10. Click on "Edit OAuth configuration" button.
32+
11. Configure the application as OAuth client by selecting "Configure this application as a client now" radio button.
33+
12. Select "Authorization code" grant type. If you are planning to use the same OAuth client application for token exchange, select "Client credentials" grant type as well. In the sample, we will use the same client.
34+
13. For Authorization grant type, select redirect URL. This is, in most cases, will be MCP server URL followed by "/oauth/callback".
35+
36+
![OAuth Configuration for an Integrated Application](./ocioauthconfiguration.png)
37+
38+
14. Click on "Submit" button to update OAuth configuration for the client application.
39+
**Note: You don't need to do any special configuration to support PKCE for the OAuth client.**
40+
15. Make sure to Activate the client application.
41+
16. Note down client ID and client secret for the application. Update .env file and replace IAM_CLIENT_ID and IAM_CLIENT_SECRET values.
42+
17. IAM_DOMAIN in the env file is the Identity domain URL that you chose for the MCP server.
43+
44+
### Token Exchange Setup (Only if MCP server needs to talk to OCI Control Plane)
45+
46+
Token exchange helps you exchange a logged-in user's OCI IAM token for an OCI control plane session token, also known as UPST (User Principal Session Token). To learn more about token exchange, refer to my [Workload Identity Federation Blog](https://www.ateam-oracle.com/post/workload-identity-federation)
47+
48+
For token exchange, we need to configure Identity propagation trust. The blog above discusses setting up the trust using REST APIs. However, you can also use OCI CLI. Before using the CLI command below, ensure that you have created a token exchange OAuth client. In most cases, you can use the same OAuth client that you created above.
49+
50+
```bash
51+
oci identity-domains identity-propagation-trust create \
52+
--schemas '["urn:ietf:params:scim:schemas:oracle:idcs:IdentityPropagationTrust"]' \
53+
--public-key-endpoint "https://${IDCS_DOMAIN}/admin/v1/SigningCert/jwk" \
54+
--name "For Token Exchange" --type "JWT" \
55+
--issuer "https://identity.oraclecloud.com/" --active true \
56+
--endpoint "https://${IDCS_DOMAIN}" \
57+
--subject-claim-name "sub" --allow-impersonation false \
58+
--subject-mapping-attribute "username" \
59+
--subject-type "User" --client-claim-name "iss" \
60+
--client-claim-values '["https://identity.oraclecloud.com/"]' \
61+
--oauth-clients '["{IDCS_CLIENT_ID}"]'
62+
```

server/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
## Getting started
44

5-
### Create IDCS domain
5+
### Create IAM Domain
6+
7+
### IAM Domain Configuration
8+
9+
Follow Steps from [IAM Domain Configuration](./IAMConfig.md) document.
610

711
### Prepare server
812

@@ -12,7 +16,7 @@
1216
export IDCS_CLIENT_ID=<value>
1317
export IDCS_CLIENT_SECRET=<value>
1418
# this isn't a URL 👇
15-
export IDCS_DOMAIN="hostname:port"
19+
export IDCS_DOMAIN="hostname:port from IDCS Domain URL"
1620
```
1721
2. Start the server
1822
```bash

server/client.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
client = Client("http://localhost:5000/mcp", auth=token or oauth)
1818

19-
2019
async def main():
2120
async with client:
2221
await client.ping()
@@ -30,14 +29,9 @@ async def main():
3029
print(f"Prompts: {prompts}")
3130

3231
# call list regions tool
33-
# result = await client.call_tool("list_regions", {})
34-
result = await client.call_tool(
35-
"run_oci_command",
36-
{
37-
"command": "iam region list",
38-
},
39-
)
32+
result = await client.call_tool("list_regions", {"region": "us-ashburn-1"})
33+
result = await client.call_tool("get_os_namespace", {"region": "us-ashburn-1"})
4034
print(result)
4135

42-
43-
asyncio.run(main())
36+
if __name__ == "__main__":
37+
asyncio.run(main())

server/ociaddapplication.png

179 KB
Loading

server/ocieditdomainsettings.png

37.7 KB
Loading
67.8 KB
Loading

server/ocioauthconfiguration.png

59.7 KB
Loading

server/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.13"
77
dependencies = [
8-
"fastmcp==2.12.4",
8+
"fastmcp==2.13.0.2",
99
"flask>=3.1.2",
10-
"oci>=2.160.2",
10+
"oci>=2.163.0",
1111
"pyjwt>=2.10.1",
1212
"requests>=2.32.5",
1313
]

0 commit comments

Comments
 (0)