mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
feat(mcp): add OAuth 2.1 support (#505)
* feat(mcp): add OAuth 2.1 support with dynamic client registration * feat(api): alias bare oauth-authorization-server discovery endpoint * fix(auth): preserve user session on OAuth sign-in redirect to consent
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
"@anthropic-ai/sandbox-runtime": "0.0.74",
|
||||
"@aws-sdk/client-s3": "3.1121.0",
|
||||
"@aws-sdk/s3-request-presigner": "3.1121.0",
|
||||
"@better-auth/mcp": "1.7.12",
|
||||
"@better-auth/oauth-provider": "1.7.12",
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"@earendil-works/pi-ai": "0.82.1",
|
||||
"@google/genai": "2.28.0",
|
||||
@@ -37,7 +39,7 @@
|
||||
"@sinclair/typebox": "0.34.52",
|
||||
"adm-zip": "0.6.0",
|
||||
"ai": "7.0.84",
|
||||
"better-auth": "1.6.11",
|
||||
"better-auth": "1.7.12",
|
||||
"csv-parse": "7.0.2",
|
||||
"date-fns": "4.4.0",
|
||||
"dotenv": "17.4.2",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks'
|
||||
import { betterAuth } from 'better-auth'
|
||||
import { jwt } from 'better-auth/plugins'
|
||||
import { mcp } from '@better-auth/mcp'
|
||||
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { teamService } from '@shumai/core/src/team/team'
|
||||
@@ -14,10 +16,28 @@ interface GeneratedResetLink {
|
||||
|
||||
const resetLinkStorage = new AsyncLocalStorage<GeneratedResetLink>()
|
||||
|
||||
export const authBaseUrl =
|
||||
process.env.BETTER_AUTH_URL || `http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`
|
||||
export const mcpResource = `${authBaseUrl}/mcp`
|
||||
export { hashPassword } from 'better-auth/crypto'
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: 'postgresql',
|
||||
}),
|
||||
plugins: [
|
||||
jwt(),
|
||||
mcp({
|
||||
loginPage: '/login',
|
||||
consentPage: '/consent',
|
||||
resource: mcpResource,
|
||||
resources: [{ identifier: mcpResource, allowedScopes: ['mcp'] }],
|
||||
scopes: ['openid', 'profile', 'email', 'offline_access', 'mcp'],
|
||||
allowDynamicClientRegistration: true,
|
||||
allowUnauthenticatedClientRegistration: true,
|
||||
clientRegistrationDefaultApplicationType: 'infer',
|
||||
}),
|
||||
],
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
minPasswordLength: 3,
|
||||
@@ -33,8 +53,7 @@ export const auth = betterAuth({
|
||||
},
|
||||
secret: process.env.BETTER_AUTH_SECRET,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
baseURL:
|
||||
process.env.BETTER_AUTH_URL || `http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`,
|
||||
baseURL: authBaseUrl,
|
||||
basePath: '/api/auth',
|
||||
trustedOrigins: [
|
||||
`http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`,
|
||||
|
||||
Reference in New Issue
Block a user