-
Notifications
You must be signed in to change notification settings - Fork 18
Enforce scoped auth for EPCIS MCP tools #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71c33e8
0929945
9e01271
45713ce
48ac988
1bf75c2
9de0a74
cccd81e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,14 @@ const version = "1.0.0"; | |
| const { oauthPlugin, openapiSecurityScheme } = createOAuthPlugin({ | ||
| storage: new SqliteOAuthStorageProvider(db), | ||
| issuerUrl: new URL(process.env.EXPO_PUBLIC_MCP_URL), | ||
| scopesSupported: ["mcp", "llm", "scope123", "blob"], | ||
| scopesSupported: [ | ||
| "mcp", | ||
| "llm", | ||
| "scope123", | ||
| "blob", | ||
| "epcis.read", | ||
| "epcis.write", | ||
| ], | ||
| loginPageUrl: new URL(process.env.EXPO_PUBLIC_APP_URL + "/login"), | ||
| schema: userCredentialsSchema, | ||
| async login(credentials) { | ||
|
|
@@ -101,6 +108,12 @@ const app = createPluginServer({ | |
| oauthPlugin, | ||
| (_, __, api) => { | ||
| api.use("/mcp", authorized(["mcp"])); | ||
| api.use("/mcp", (req, res, next) => { | ||
| if (res.locals.auth) { | ||
| (req as any).auth = res.locals.auth; | ||
| } | ||
| next(); | ||
| }); | ||
| api.use("/llm", authorized(["llm"])); | ||
| api.use("/blob", authorized(["blob"])); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Bug: |
||
| api.use("/change-password", authorized([])); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { createPluginServer, defaultPlugin } from "@dkg/plugins"; | |
| import { authorized, createOAuthPlugin } from "@dkg/plugin-oauth"; | ||
| import dkgEssentialsPlugin from "@dkg/plugin-dkg-essentials"; | ||
| import createFsBlobStorage from "@dkg/plugin-dkg-essentials/createFsBlobStorage"; | ||
| import epcisPlugin, { applyEpcisHttpScopeGuards } from "@dkg/plugin-epcis"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Issue: This new import relies on
zsculac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { | ||
| createInMemoryBlobStorage, | ||
| createMockDkgClient, | ||
|
|
@@ -84,7 +85,14 @@ export async function createTestServer(config: TestServerConfig = {}): Promise<{ | |
| const { oauthPlugin, openapiSecurityScheme } = createOAuthPlugin({ | ||
| storage: testDatabase.oauthStorage, | ||
| issuerUrl: new URL(oauthUrls.issuerUrl), | ||
| scopesSupported: ["mcp", "llm", "scope123", "blob"], | ||
| scopesSupported: [ | ||
| "mcp", | ||
| "llm", | ||
| "scope123", | ||
| "blob", | ||
| "epcis.read", | ||
| "epcis.write", | ||
| ], | ||
| loginPageUrl: new URL(oauthUrls.loginPageUrl), | ||
| schema: userCredentialsSchema, | ||
| async login(credentials: { email: string; password: string }) { | ||
|
|
@@ -149,7 +157,14 @@ export async function createTestServer(config: TestServerConfig = {}): Promise<{ | |
| oauthPlugin, | ||
| // Same authorization middleware as real app | ||
| (_, __, api) => { | ||
| applyEpcisHttpScopeGuards(api, authorized); | ||
| api.use("/mcp", authorized(["mcp"])); | ||
| api.use("/mcp", (req, res, next) => { | ||
| if (res.locals.auth) { | ||
| (req as any).auth = res.locals.auth; | ||
| } | ||
| next(); | ||
| }); | ||
| api.use("/llm", authorized(["llm"])); | ||
| api.use("/blob", authorized(["blob"])); | ||
| }, | ||
|
|
@@ -161,6 +176,7 @@ export async function createTestServer(config: TestServerConfig = {}): Promise<{ | |
| }); | ||
| }, | ||
| dkgEssentialsPlugin, | ||
| epcisPlugin, | ||
| // DKG Publisher Plugin for API contract testing | ||
| mockDkgPublisherPlugin, // Mock version - tests interfaces without database | ||
| // Test the namespace functionality | ||
|
|
@@ -232,6 +248,7 @@ export async function startTestServer(config: TestServerConfig = {}): Promise<{ | |
|
|
||
| const actualPort = (server.address() as any)?.port || port; | ||
| const url = `http://localhost:${actualPort}`; | ||
| process.env.EXPO_PUBLIC_MCP_URL = url; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Issue:
zsculac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| console.log(`Test server running at ${url}`); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.