Merge pull request 'refactor_server' (#340) from refactor_server into @hera/dev
Reviewed-on: daoyoucloud/tachycode#340
This commit is contained in:
commit
3ed284f94a
@ -1,7 +1,7 @@
|
||||
import { FormOutlined } from '@ant-design/icons';
|
||||
import { FormLayout } from '@formily/antd-v5';
|
||||
import { SchemaOptionsContext } from '@formily/react';
|
||||
import { createFormBlockSchema, useAPIClient, useCollectionManager_deprecated } from '@nocobase/client';
|
||||
import { createFormBlockSchema, useAPIClient, useCollectionManager } from '@nocobase/client';
|
||||
import {
|
||||
DataBlockInitializer,
|
||||
FormDialog,
|
||||
@ -12,7 +12,7 @@ import {
|
||||
useSchemaInitializerItem,
|
||||
} from '@nocobase/client';
|
||||
import React, { useContext } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useTranslation } from '../locale';
|
||||
|
||||
export const SettingBlockInitializer = () => {
|
||||
const { insert } = useSchemaInitializer();
|
||||
@ -20,7 +20,7 @@ export const SettingBlockInitializer = () => {
|
||||
const options = useContext(SchemaOptionsContext);
|
||||
const { theme } = useGlobalTheme();
|
||||
const itemConfig = useSchemaInitializerItem();
|
||||
const { getCollection } = useCollectionManager_deprecated();
|
||||
const cm = useCollectionManager();
|
||||
const api = useAPIClient();
|
||||
return (
|
||||
<DataBlockInitializer
|
||||
@ -28,11 +28,11 @@ export const SettingBlockInitializer = () => {
|
||||
componentType={'FormItem'}
|
||||
icon={<FormOutlined />}
|
||||
onCreateBlockSchema={async ({ item }) => {
|
||||
const collection = getCollection(item.name);
|
||||
const titleField = collection.options.titleField;
|
||||
const collection = cm.getCollection(item.name);
|
||||
const titleField = collection.titleField;
|
||||
const result = await api.resource(collection.name).list();
|
||||
const values = await FormDialog(
|
||||
t('添加单条数据展示区块'),
|
||||
t('Pick a data entry for viewing and editing'),
|
||||
() => {
|
||||
return (
|
||||
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
||||
@ -41,7 +41,7 @@ export const SettingBlockInitializer = () => {
|
||||
schema={{
|
||||
properties: {
|
||||
id: {
|
||||
title: t('选择数据'),
|
||||
title: t('Please select'),
|
||||
enum: result.data.data.map((item) => {
|
||||
return {
|
||||
label: item[titleField],
|
||||
|
@ -15,5 +15,7 @@
|
||||
"System setting": "System setting",
|
||||
"classical": "classical",
|
||||
"Signature input": "Signature input",
|
||||
"Pick a data entry for viewing and editing": "Pick a data entry for viewing and editing",
|
||||
"Please select": "Please select",
|
||||
"HomePage Config": "HomePage Config"
|
||||
}
|
||||
|
@ -15,5 +15,7 @@
|
||||
"System setting": "系统设置",
|
||||
"classical": "经典版",
|
||||
"Signature input": "手写签名",
|
||||
"Pick a data entry for viewing and editing": "选择一条数据用于查看与编辑",
|
||||
"Please select": "请选择",
|
||||
"HomePage Config": "主页配置"
|
||||
}
|
||||
|
2
packages/plugins/@hera/plugin-oidc/.npmignore
Normal file
2
packages/plugins/@hera/plugin-oidc/.npmignore
Normal file
@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/src
|
1
packages/plugins/@hera/plugin-oidc/README.md
Normal file
1
packages/plugins/@hera/plugin-oidc/README.md
Normal file
@ -0,0 +1 @@
|
||||
# @hera/plugin-oidc
|
2
packages/plugins/@hera/plugin-oidc/client.d.ts
vendored
Normal file
2
packages/plugins/@hera/plugin-oidc/client.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './dist/client';
|
||||
export { default } from './dist/client';
|
1
packages/plugins/@hera/plugin-oidc/client.js
Normal file
1
packages/plugins/@hera/plugin-oidc/client.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./dist/client/index.js');
|
14
packages/plugins/@hera/plugin-oidc/package.json
Normal file
14
packages/plugins/@hera/plugin-oidc/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@hera/plugin-oidc",
|
||||
"version": "0.20.0-alpha.7",
|
||||
"main": "dist/server/index.js",
|
||||
"devDependencies": {
|
||||
"@koa/router": "^12.0.1",
|
||||
"@types/koa__router": "^12.0.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nocobase/client": "0.x",
|
||||
"@nocobase/server": "0.x",
|
||||
"@nocobase/test": "0.x"
|
||||
}
|
||||
}
|
2
packages/plugins/@hera/plugin-oidc/server.d.ts
vendored
Normal file
2
packages/plugins/@hera/plugin-oidc/server.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './dist/server';
|
||||
export { default } from './dist/server';
|
1
packages/plugins/@hera/plugin-oidc/server.js
Normal file
1
packages/plugins/@hera/plugin-oidc/server.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./dist/server/index.js');
|
21
packages/plugins/@hera/plugin-oidc/src/client/index.tsx
Normal file
21
packages/plugins/@hera/plugin-oidc/src/client/index.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { Plugin } from '@nocobase/client';
|
||||
|
||||
export class PluginOidcClient extends Plugin {
|
||||
async afterAdd() {
|
||||
// await this.app.pm.add()
|
||||
}
|
||||
|
||||
async beforeLoad() {}
|
||||
|
||||
// You can get and modify the app instance here
|
||||
async load() {
|
||||
console.log(this.app);
|
||||
// this.app.addComponents({})
|
||||
// this.app.addScopes({})
|
||||
// this.app.addProvider()
|
||||
// this.app.addProviders()
|
||||
// this.app.router.add()
|
||||
}
|
||||
}
|
||||
|
||||
export default PluginOidcClient;
|
2
packages/plugins/@hera/plugin-oidc/src/index.ts
Normal file
2
packages/plugins/@hera/plugin-oidc/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './server';
|
||||
export { default } from './server';
|
1
packages/plugins/@hera/plugin-oidc/src/server/index.ts
Normal file
1
packages/plugins/@hera/plugin-oidc/src/server/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { default } from './plugin';
|
218
packages/plugins/@hera/plugin-oidc/src/server/plugin.ts
Normal file
218
packages/plugins/@hera/plugin-oidc/src/server/plugin.ts
Normal file
@ -0,0 +1,218 @@
|
||||
import { Plugin } from '@nocobase/server';
|
||||
import Router from '@koa/router';
|
||||
|
||||
export class PluginOidcServer extends Plugin {
|
||||
async afterAdd() {}
|
||||
|
||||
async beforeLoad() {}
|
||||
|
||||
async load() {
|
||||
const router = new Router();
|
||||
|
||||
router.get('/oidc/hello', async (ctx, next) => {
|
||||
ctx.body = {
|
||||
message: 'hello from koa router',
|
||||
};
|
||||
});
|
||||
// this.app.use(router.routes());
|
||||
this.app.use(async (ctx, next) => {
|
||||
console.log('------------------- - - - -');
|
||||
});
|
||||
|
||||
// router.use(async (ctx, next) => {
|
||||
// ctx.set('cache-control', 'no-store');
|
||||
// try {
|
||||
// await next();
|
||||
// } catch (err) {
|
||||
// console.log('------------------')
|
||||
// console.error(err)
|
||||
// if (err instanceof SessionNotFound) {
|
||||
// ctx.status = err.status;
|
||||
// const { message: error, error_description } = err;
|
||||
// await defaults.renderError(ctx, { error, error_description }, err);
|
||||
// } else {
|
||||
// throw err;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// router.get('/interaction/:uid', async (ctx, next) => {
|
||||
// const {
|
||||
// uid, prompt, params, session,
|
||||
// } = await provider.interactionDetails(ctx.req, ctx.res);
|
||||
// const client = await provider.Client.find(params.client_id);
|
||||
|
||||
// switch (prompt.name) {
|
||||
// case 'login': {
|
||||
// return ctx.render('login', {
|
||||
// client,
|
||||
// uid,
|
||||
// details: prompt.details,
|
||||
// params,
|
||||
// title: 'Sign-in',
|
||||
// google: ctx.google,
|
||||
// session: session ? debug(session) : undefined,
|
||||
// dbg: {
|
||||
// params: debug(params),
|
||||
// prompt: debug(prompt),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// case 'consent': {
|
||||
// return ctx.render('interaction', {
|
||||
// client,
|
||||
// uid,
|
||||
// details: prompt.details,
|
||||
// params,
|
||||
// title: 'Authorize',
|
||||
// session: session ? debug(session) : undefined,
|
||||
// dbg: {
|
||||
// params: debug(params),
|
||||
// prompt: debug(prompt),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// default:
|
||||
// return next();
|
||||
// }
|
||||
// });
|
||||
|
||||
// const body = bodyParser({
|
||||
// text: false, json: false, patchNode: true, patchKoa: true,
|
||||
// });
|
||||
|
||||
// router.get('/interaction/callback/google', (ctx) => {
|
||||
// const nonce = ctx.res.locals.cspNonce;
|
||||
// return ctx.render('repost', { layout: false, upstream: 'google', nonce });
|
||||
// });
|
||||
|
||||
// router.post('/interaction/:uid/login', body, async (ctx) => {
|
||||
// const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res);
|
||||
// assert.equal(name, 'login');
|
||||
|
||||
// const account = await Account.findByLogin(ctx.request.body.login);
|
||||
|
||||
// const result = {
|
||||
// login: {
|
||||
// accountId: account.accountId,
|
||||
// },
|
||||
// };
|
||||
|
||||
// return provider.interactionFinished(ctx.req, ctx.res, result, {
|
||||
// mergeWithLastSubmission: false,
|
||||
// });
|
||||
// });
|
||||
|
||||
// router.post('/interaction/:uid/federated', body, async (ctx) => {
|
||||
// const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res);
|
||||
// assert.equal(name, 'login');
|
||||
|
||||
// const path = `/interaction/${ctx.params.uid}/federated`;
|
||||
|
||||
// switch (ctx.request.body.upstream) {
|
||||
// case 'google': {
|
||||
// const callbackParams = ctx.google.callbackParams(ctx.req);
|
||||
|
||||
// // init
|
||||
// if (!Object.keys(callbackParams).length) {
|
||||
// const state = ctx.params.uid;
|
||||
// const nonce = crypto.randomBytes(32).toString('hex');
|
||||
|
||||
// ctx.cookies.set('google.nonce', nonce, { path, sameSite: 'strict' });
|
||||
|
||||
// ctx.status = 303;
|
||||
// return ctx.redirect(ctx.google.authorizationUrl({
|
||||
// state, nonce, scope: 'openid email profile',
|
||||
// }));
|
||||
// }
|
||||
|
||||
// // callback
|
||||
// const nonce = ctx.cookies.get('google.nonce');
|
||||
// ctx.cookies.set('google.nonce', null, { path });
|
||||
|
||||
// const tokenset = await ctx.google.callback(undefined, callbackParams, { state: ctx.params.uid, nonce, response_type: 'id_token' });
|
||||
// const account = await Account.findByFederated('google', tokenset.claims());
|
||||
|
||||
// const result = {
|
||||
// login: {
|
||||
// accountId: account.accountId,
|
||||
// },
|
||||
// };
|
||||
// return provider.interactionFinished(ctx.req, ctx.res, result, {
|
||||
// mergeWithLastSubmission: false,
|
||||
// });
|
||||
// }
|
||||
// default:
|
||||
// return undefined;
|
||||
// }
|
||||
// });
|
||||
|
||||
// router.post('/interaction/:uid/confirm', body, async (ctx) => {
|
||||
// const interactionDetails = await provider.interactionDetails(ctx.req, ctx.res);
|
||||
// const { prompt: { name, details }, params, session: { accountId } } = interactionDetails;
|
||||
// assert.equal(name, 'consent');
|
||||
|
||||
// let { grantId } = interactionDetails;
|
||||
// let grant;
|
||||
|
||||
// if (grantId) {
|
||||
// // we'll be modifying existing grant in existing session
|
||||
// grant = await provider.Grant.find(grantId);
|
||||
// } else {
|
||||
// // we're establishing a new grant
|
||||
// grant = new provider.Grant({
|
||||
// accountId,
|
||||
// clientId: params.client_id,
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (details.missingOIDCScope) {
|
||||
// grant.addOIDCScope(details.missingOIDCScope.join(' '));
|
||||
// }
|
||||
// if (details.missingOIDCClaims) {
|
||||
// grant.addOIDCClaims(details.missingOIDCClaims);
|
||||
// }
|
||||
// if (details.missingResourceScopes) {
|
||||
// for (const [indicator, scope] of Object.entries(details.missingResourceScopes)) {
|
||||
// grant.addResourceScope(indicator, scope.join(' '));
|
||||
// }
|
||||
// }
|
||||
|
||||
// grantId = await grant.save();
|
||||
|
||||
// const consent = {};
|
||||
// if (!interactionDetails.grantId) {
|
||||
// // we don't have to pass grantId to consent, we're just modifying existing one
|
||||
// consent.grantId = grantId;
|
||||
// }
|
||||
|
||||
// const result = { consent };
|
||||
// return provider.interactionFinished(ctx.req, ctx.res, result, {
|
||||
// mergeWithLastSubmission: true,
|
||||
// });
|
||||
// });
|
||||
|
||||
// router.get('/interaction/:uid/abort', async (ctx) => {
|
||||
// const result = {
|
||||
// error: 'access_denied',
|
||||
// error_description: 'End-User aborted interaction',
|
||||
// };
|
||||
|
||||
// return provider.interactionFinished(ctx.req, ctx.res, result, {
|
||||
// mergeWithLastSubmission: false,
|
||||
// });
|
||||
// });
|
||||
|
||||
// return router;
|
||||
}
|
||||
|
||||
async install() {}
|
||||
|
||||
async afterEnable() {}
|
||||
|
||||
async afterDisable() {}
|
||||
|
||||
async remove() {}
|
||||
}
|
||||
|
||||
export default PluginOidcServer;
|
Loading…
Reference in New Issue
Block a user