Skip to content

Add issuer as an initialization parameter #9

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/express-mcp-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const port = process.env.PORT || 3000;

const mcpAuthServer = new McpAuthServer({
baseUrl: process.env.BASE_URL as string,
issuer: process.env.ISSUER as string,
Copy link
Member

@brionmario brionmario Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this mandatory?

IMO, we can default to inferring the base part from baseUrl and let the users override the issuer endpoint as an optional thing?

const mcpAuthServer = new McpAuthServer({
  baseUrl: process.env.BASE_URL as string,
  endpoints: { -> // optional
      issuer: process.env.ISSUER as string,
  }
}

});

app.use(express.json());
Expand Down
1 change: 1 addition & 0 deletions examples/express-mcp-vet-ai-assist-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const app: Express = express();

const mcpAuthServer: McpAuthServer = new McpAuthServer({
baseUrl: process.env.BASE_URL as string,
issuer: process.env.ISSUER as string,
});

app.use(express.json());
Expand Down
9 changes: 8 additions & 1 deletion packages/mcp-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const app = express();
// Initialize McpAuthServer with baseUrl
const mcpAuthServer = new McpAuthServer({
baseUrl: process.env.BASE_URL as string,
issuer: process.env.ISSUER as string
});

app.use(express.json());
Expand All @@ -65,7 +66,10 @@ Creates a new instance of the MCP authentication server with the given configura
```typescript
import {McpAuthServer} from '@asgardeo/mcp-express';

const mcpAuthServer = new McpAuthServer({baseUrl: 'https://auth.example.com'});
const mcpAuthServer = new McpAuthServer({
baseUrl: 'https://auth.example.com',
issuer: 'https://auth.example.com/oauth2/token'
});
```

#### mcpAuthServer.router()
Expand Down Expand Up @@ -95,6 +99,8 @@ The server can be configured with the following option:
interface McpAuthServerOptions {
/** Base URL of the authorization server */
baseUrl: string;
/** Issuer of the authorization server */
issuer: string;
}
```

Expand All @@ -119,6 +125,7 @@ const app: Express = express();
// Initialize McpAuthServer
const mcpAuthServer = new McpAuthServer({
baseUrl: process.env.BASE_URL as string,
issuer: process.env.ISSUER as string,
});

app.use(express.json());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function bearerAuthMiddleware(options: McpAuthOptions) {
options: {
audience: options?.audience,
clockTolerance: 60,
issuer: `${issuerBase}/oauth2/token`,
issuer: `${options.issuer}`,
},
};

Expand Down
4 changes: 2 additions & 2 deletions packages/mcp-express/src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {getProtectedResourceMetadata} from '../controllers/protected-resource';

export default function AuthRouter(options: McpAuthOptions): express.Router {
const router: express.Router = express.Router();
const {baseUrl} = options;
const {baseUrl, issuer} = options;
if (!baseUrl) {
throw new Error('baseUrl must be provided');
}

router.use(
PROTECTED_RESOURCE_URL,
getProtectedResourceMetadata({
authorizationServers: [baseUrl],
authorizationServers: [issuer],
resource: 'https://api.example.com',
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/mcp-node/src/models/mcp-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
export interface McpAuthOptions {
audience?: string;
baseUrl: string;
issuer: string;
}
Loading