From 8fc96b7918689de6608f67abeeb08a0c116c0328 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 27 Jun 2023 17:13:14 +0800 Subject: [PATCH] refactor: fix oauth demo which has little problem --- pnpm-lock.yaml | 18 +++++++++++++----- server/services/openapi/oidc/oidc.service.ts | 10 ++++++++++ .../test/demo/openapi-client-simple/index.ts | 8 +++++--- .../demo/openapi-client-simple/package.json | 5 ++++- server/test/demo/openapi-client/index.ts | 6 +++--- server/test/demo/openapi-client/package.json | 5 ++++- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d0faac2..312db686 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -574,7 +574,7 @@ importers: version: 0.32.11 zustand: specifier: ^4.3.6 - version: 4.3.6(immer@9.0.15)(react@18.2.0) + version: 4.3.6(immer@9.0.21)(react@18.2.0) devDependencies: '@types/crc': specifier: ^3.4.0 @@ -1875,7 +1875,7 @@ importers: version: 5.3.6(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0) zustand: specifier: ^4.3.6 - version: 4.3.6(immer@9.0.15)(react@18.2.0) + version: 4.3.6(immer@9.0.21)(react@18.2.0) server/plugins/com.msgbyte.getui: dependencies: @@ -2053,7 +2053,7 @@ importers: version: 5.3.6(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0) zustand: specifier: ^4.3.6 - version: 4.3.6(immer@9.0.15)(react@18.2.0) + version: 4.3.6(immer@9.0.21)(react@18.2.0) server/plugins/com.msgbyte.welcome: dependencies: @@ -2125,6 +2125,10 @@ importers: openid-client: specifier: ^5.1.5 version: 5.3.2 + devDependencies: + ts-node: + specifier: 10.9.1 + version: 10.9.1(@types/node@18.11.9)(typescript@4.9.4) server/test/demo/openapi-client-simple: dependencies: @@ -2134,6 +2138,10 @@ importers: express: specifier: ^4.17.2 version: 4.18.2 + devDependencies: + ts-node: + specifier: 10.9.1 + version: 10.9.1(@types/node@18.11.9)(typescript@4.9.4) website: dependencies: @@ -21749,10 +21757,10 @@ packages: /immer@9.0.15: resolution: {integrity: sha512-2eB/sswms9AEUSkOm4SbV5Y7Vmt/bKRwByd52jfLkW4OLYeaTP3EEiJ9agqU0O/tq6Dk62Zfj+TJSqfm1rLVGQ==} + dev: false /immer@9.0.21: resolution: {integrity: sha512-bc4NBHqOqSfRW7POMkHd51LvClaeMXpm8dx0e8oE2GORbq5aRK7Bxl4FyzVLdGtLmvLKL7BTDBG5ACQm4HWjTA==} - dev: false /import-fresh@2.0.0: resolution: {integrity: sha512-eZ5H8rcgYazHbKC3PG4ClHNykCSxtAhxSSEM+2mb+7evD2CKF5V7c0dNum7AdpDh0ZdICwZY9sRSn8f+KH96sg==} @@ -36412,6 +36420,7 @@ packages: immer: 9.0.15 react: 18.2.0 use-sync-external-store: 1.2.0(react@18.2.0) + dev: false /zustand@4.3.6(immer@9.0.21)(react@18.2.0): resolution: {integrity: sha512-6J5zDxjxLE+yukC2XZWf/IyWVKnXT9b9HUv09VJ/bwGCpKNcaTqp7Ws28Xr8jnbvnZcdRaidztAPsXFBIqufiw==} @@ -36428,7 +36437,6 @@ packages: immer: 9.0.21 react: 18.2.0 use-sync-external-store: 1.2.0(react@18.2.0) - dev: false /zwitch@1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} diff --git a/server/services/openapi/oidc/oidc.service.ts b/server/services/openapi/oidc/oidc.service.ts index d8246890..5a6acf17 100644 --- a/server/services/openapi/oidc/oidc.service.ts +++ b/server/services/openapi/oidc/oidc.service.ts @@ -6,6 +6,7 @@ import path from 'path'; import assert from 'assert'; import qs from 'qs'; import _ from 'lodash'; +import serve from 'serve-static'; import { TcOIDCAdapter } from './adapter'; import { claimUserInfo } from './account'; import type { UserLoginRes } from '../../../models/user/user'; @@ -300,6 +301,15 @@ class OIDCService extends TcService { 'GET /.well-known/openid-configuration': providerRoute, }, }, + { + // For css file in development + path: '/', + authentication: false, + authorization: false, + use: [serve('public')], + whitelist: [], + autoAliases: false, + }, ]; } diff --git a/server/test/demo/openapi-client-simple/index.ts b/server/test/demo/openapi-client-simple/index.ts index d1b2e1f7..f05228f4 100644 --- a/server/test/demo/openapi-client-simple/index.ts +++ b/server/test/demo/openapi-client-simple/index.ts @@ -7,8 +7,8 @@ const port = 8080; const API = process.env.API || 'http://localhost:11001'; const clientUrl = `http://localhost:${port}`; -const clientId = process.env.ID || 'tc_61f5270008e0635f67868f01'; -const clientSecret = process.env.SECRET || 'PDnLVsNnFyqWRS0QXYeaHDlE8KwgQLqv'; +const clientId = process.env.ID || 'tc_649aa2179e97b8b3b2d1004f'; +const clientSecret = process.env.SECRET || '4Pt4lccOaztJROs-VhmQf8XBU89-z8rr'; console.log('config:', { API, @@ -80,6 +80,8 @@ app.get('/cb', async (req, res, next) => { }); app.listen(port, () => { - console.log(`请确保回调已经被注册在OIDC服务端的白名单中: ${clientUrl}/cb`); + console.log( + `请确保第三方登录功能已启动并且回调已经被注册在OIDC服务端的白名单中: ${clientUrl}/cb` + ); console.log(`测试服务地址: http://127.0.0.1:${port}`); }); diff --git a/server/test/demo/openapi-client-simple/package.json b/server/test/demo/openapi-client-simple/package.json index d1c6917e..426abccb 100644 --- a/server/test/demo/openapi-client-simple/package.json +++ b/server/test/demo/openapi-client-simple/package.json @@ -9,9 +9,12 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "GPL-3.0", + "license": "MIT", "dependencies": { "axios": "^0.26.0", "express": "^4.17.2" + }, + "devDependencies": { + "ts-node": "10.9.1" } } diff --git a/server/test/demo/openapi-client/index.ts b/server/test/demo/openapi-client/index.ts index ed3f3f76..5d2fb399 100644 --- a/server/test/demo/openapi-client/index.ts +++ b/server/test/demo/openapi-client/index.ts @@ -7,8 +7,8 @@ const port = 8080; const API = process.env.API || 'http://localhost:11001'; const clientUrl = `http://localhost:${port}`; -const clientId = process.env.ID || 'tc_61f5270008e0635f67868f01'; -const clientSecret = process.env.SECRET || 'PDnLVsNnFyqWRS0QXYeaHDlE8KwgQLqv'; +const clientId = process.env.ID || 'tc_649aa2179e97b8b3b2d1004f'; +const clientSecret = process.env.SECRET || '4Pt4lccOaztJROs-VhmQf8XBU89-z8rr'; console.log('config:', { API, @@ -36,7 +36,7 @@ const request = axios.create({ (async () => { const tailchatIssuer = await Issuer.discover( - 'https://paw-server-nightly.moonrailgun.com/open/' + 'https://tailchat-nightly.moonrailgun.com/open/' ); console.log( 'Discovered issuer', diff --git a/server/test/demo/openapi-client/package.json b/server/test/demo/openapi-client/package.json index 2f8a55c9..6b6568c7 100644 --- a/server/test/demo/openapi-client/package.json +++ b/server/test/demo/openapi-client/package.json @@ -9,10 +9,13 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "GPL-3.0", + "license": "MIT", "dependencies": { "axios": "^0.26.0", "express": "^4.17.2", "openid-client": "^5.1.5" + }, + "devDependencies": { + "ts-node": "10.9.1" } }