@tachybase/plugin-auth-oidc 0.23.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -0
- package/README.md +11 -0
- package/README.zh-CN.md +38 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/OIDCButton.d.ts +9 -0
- package/dist/client/Options.d.ts +2 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +3 -0
- package/dist/client/locale/index.d.ts +3 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +34 -0
- package/dist/externalVersion.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +40 -0
- package/dist/locale/es-ES.json +25 -0
- package/dist/locale/fr-FR.json +21 -0
- package/dist/locale/ko_KR.json +28 -0
- package/dist/locale/pt-BR.json +21 -0
- package/dist/locale/zh-CN.json +28 -0
- package/dist/node_modules/nanoid/.devcontainer.json +23 -0
- package/dist/node_modules/nanoid/LICENSE +20 -0
- package/dist/node_modules/nanoid/async/index.browser.cjs +69 -0
- package/dist/node_modules/nanoid/async/index.browser.js +69 -0
- package/dist/node_modules/nanoid/async/index.cjs +71 -0
- package/dist/node_modules/nanoid/async/index.d.ts +56 -0
- package/dist/node_modules/nanoid/async/index.js +71 -0
- package/dist/node_modules/nanoid/async/index.native.js +57 -0
- package/dist/node_modules/nanoid/async/package.json +12 -0
- package/dist/node_modules/nanoid/bin/nanoid.cjs +55 -0
- package/dist/node_modules/nanoid/index.browser.cjs +72 -0
- package/dist/node_modules/nanoid/index.browser.js +72 -0
- package/dist/node_modules/nanoid/index.cjs +1 -0
- package/dist/node_modules/nanoid/index.d.cts +91 -0
- package/dist/node_modules/nanoid/index.d.ts +91 -0
- package/dist/node_modules/nanoid/index.js +85 -0
- package/dist/node_modules/nanoid/nanoid.js +1 -0
- package/dist/node_modules/nanoid/non-secure/index.cjs +34 -0
- package/dist/node_modules/nanoid/non-secure/index.d.ts +33 -0
- package/dist/node_modules/nanoid/non-secure/index.js +34 -0
- package/dist/node_modules/nanoid/non-secure/package.json +6 -0
- package/dist/node_modules/nanoid/package.json +1 -0
- package/dist/node_modules/nanoid/url-alphabet/index.cjs +7 -0
- package/dist/node_modules/nanoid/url-alphabet/index.js +7 -0
- package/dist/node_modules/nanoid/url-alphabet/package.json +6 -0
- package/dist/node_modules/openid-client/lib/client.js +1884 -0
- package/dist/node_modules/openid-client/lib/device_flow_handle.js +125 -0
- package/dist/node_modules/openid-client/lib/errors.js +55 -0
- package/dist/node_modules/openid-client/lib/helpers/assert.js +24 -0
- package/dist/node_modules/openid-client/lib/helpers/base64url.js +13 -0
- package/dist/node_modules/openid-client/lib/helpers/client.js +208 -0
- package/dist/node_modules/openid-client/lib/helpers/consts.js +7 -0
- package/dist/node_modules/openid-client/lib/helpers/decode_jwt.js +27 -0
- package/dist/node_modules/openid-client/lib/helpers/deep_clone.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/defaults.js +27 -0
- package/dist/node_modules/openid-client/lib/helpers/generators.js +14 -0
- package/dist/node_modules/openid-client/lib/helpers/is_key_object.js +4 -0
- package/dist/node_modules/openid-client/lib/helpers/is_plain_object.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/issuer.js +111 -0
- package/dist/node_modules/openid-client/lib/helpers/keystore.js +298 -0
- package/dist/node_modules/openid-client/lib/helpers/merge.js +24 -0
- package/dist/node_modules/openid-client/lib/helpers/pick.js +9 -0
- package/dist/node_modules/openid-client/lib/helpers/process_response.js +71 -0
- package/dist/node_modules/openid-client/lib/helpers/request.js +200 -0
- package/dist/node_modules/openid-client/lib/helpers/unix_timestamp.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/weak_cache.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/webfinger_normalize.js +71 -0
- package/dist/node_modules/openid-client/lib/helpers/www_authenticate_parser.js +14 -0
- package/dist/node_modules/openid-client/lib/index.js +1 -0
- package/dist/node_modules/openid-client/lib/issuer.js +192 -0
- package/dist/node_modules/openid-client/lib/issuer_registry.js +3 -0
- package/dist/node_modules/openid-client/lib/passport_strategy.js +205 -0
- package/dist/node_modules/openid-client/lib/token_set.js +35 -0
- package/dist/node_modules/openid-client/package.json +1 -0
- package/dist/node_modules/openid-client/types/index.d.ts +623 -0
- package/dist/server/actions/getAuthUrl.d.ts +2 -0
- package/dist/server/actions/getAuthUrl.js +47 -0
- package/dist/server/actions/redirect.d.ts +2 -0
- package/dist/server/actions/redirect.js +55 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/migrations/20231007124508-update-autosignup.d.ts +6 -0
- package/dist/server/migrations/20231007124508-update-autosignup.js +52 -0
- package/dist/server/oidc-auth.d.ts +15 -0
- package/dist/server/oidc-auth.js +154 -0
- package/dist/server/plugin.d.ts +11 -0
- package/dist/server/plugin.js +83 -0
- package/dist/swagger/index.d.ts +143 -0
- package/dist/swagger/index.js +178 -0
- package/package.json +37 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var redirect_exports = {};
|
|
19
|
+
__export(redirect_exports, {
|
|
20
|
+
redirect: () => redirect
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(redirect_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
const redirect = async (ctx, next) => {
|
|
25
|
+
const {
|
|
26
|
+
params: { state }
|
|
27
|
+
} = ctx.action;
|
|
28
|
+
const search = new URLSearchParams(decodeURIComponent(state));
|
|
29
|
+
const authenticator = search.get("name");
|
|
30
|
+
const appName = search.get("app");
|
|
31
|
+
const redirect2 = search.get("redirect") || "/admin";
|
|
32
|
+
let prefix = process.env.APP_PUBLIC_PATH || "";
|
|
33
|
+
if (appName && appName !== "main") {
|
|
34
|
+
const appSupervisor = import_server.AppSupervisor.getInstance();
|
|
35
|
+
if ((appSupervisor == null ? void 0 : appSupervisor.runningMode) !== "single") {
|
|
36
|
+
prefix += `apps/${appName}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const auth = await ctx.app.authManager.get(authenticator, ctx);
|
|
40
|
+
if (prefix.endsWith("/")) {
|
|
41
|
+
prefix = prefix.slice(0, -1);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const { token } = await auth.signIn();
|
|
45
|
+
ctx.redirect(`${prefix}${redirect2}?authenticator=${authenticator}&token=${token}`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
ctx.logger.error("OIDC auth error", { error });
|
|
48
|
+
ctx.redirect(`${prefix}/signin?redirect=${redirect2}&authenticator=${authenticator}&error=${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
await next();
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
redirect
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var update_autosignup_exports = {};
|
|
19
|
+
__export(update_autosignup_exports, {
|
|
20
|
+
default: () => UpdateAutoSignupMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_autosignup_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
var import_constants = require("../../constants");
|
|
25
|
+
class UpdateAutoSignupMigration extends import_server.Migration {
|
|
26
|
+
appVersion = "<0.14.0-alpha.8";
|
|
27
|
+
async up() {
|
|
28
|
+
const result = await this.app.version.satisfies("<=0.14.0-alpha.8");
|
|
29
|
+
if (!result) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const r = this.db.getRepository("authenticators");
|
|
33
|
+
const items = await r.find({
|
|
34
|
+
filter: {
|
|
35
|
+
authType: import_constants.authType
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
await this.db.sequelize.transaction(async (transaction) => {
|
|
39
|
+
for (const item of items) {
|
|
40
|
+
let options = item.options;
|
|
41
|
+
options = {
|
|
42
|
+
public: { autoSignup: true, ...options.public },
|
|
43
|
+
oidc: { userBindField: "email", ...options.oidc }
|
|
44
|
+
};
|
|
45
|
+
item.set("options", options);
|
|
46
|
+
await item.save({ transaction });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async down() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthConfig, BaseAuth } from '@tachybase/auth';
|
|
2
|
+
export { Model } from '@tachybase/database';
|
|
3
|
+
export declare class OIDCAuth extends BaseAuth {
|
|
4
|
+
constructor(config: AuthConfig);
|
|
5
|
+
getRedirectUri(): string;
|
|
6
|
+
getOptions(): any;
|
|
7
|
+
getExchangeBody(): {};
|
|
8
|
+
mapField(userInfo: {
|
|
9
|
+
[source: string]: any;
|
|
10
|
+
}): {
|
|
11
|
+
[source: string]: any;
|
|
12
|
+
};
|
|
13
|
+
createOIDCClient(): Promise<import("openid-client").BaseClient>;
|
|
14
|
+
validate(): Promise<import("@tachybase/database").Model<any, any>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var oidc_auth_exports = {};
|
|
19
|
+
__export(oidc_auth_exports, {
|
|
20
|
+
Model: () => import_database.Model,
|
|
21
|
+
OIDCAuth: () => OIDCAuth
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(oidc_auth_exports);
|
|
24
|
+
var import_auth = require("@tachybase/auth");
|
|
25
|
+
var import_openid_client = require("openid-client");
|
|
26
|
+
var import_constants = require("../constants");
|
|
27
|
+
var import_database = require("@tachybase/database");
|
|
28
|
+
class OIDCAuth extends import_auth.BaseAuth {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
const { ctx } = config;
|
|
31
|
+
super({
|
|
32
|
+
...config,
|
|
33
|
+
userCollection: ctx.db.getCollection("users")
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getRedirectUri() {
|
|
37
|
+
const ctx = this.ctx;
|
|
38
|
+
const { http, port } = this.getOptions();
|
|
39
|
+
const protocol = http ? "http" : "https";
|
|
40
|
+
const host = port ? `${ctx.hostname}${port ? `:${port}` : ""}` : ctx.host;
|
|
41
|
+
return `${protocol}://${host}${process.env.API_BASE_PATH}oidc:redirect`;
|
|
42
|
+
}
|
|
43
|
+
getOptions() {
|
|
44
|
+
var _a;
|
|
45
|
+
return ((_a = this.options) == null ? void 0 : _a.oidc) || {};
|
|
46
|
+
}
|
|
47
|
+
getExchangeBody() {
|
|
48
|
+
const options = this.getOptions();
|
|
49
|
+
const { exchangeBodyKeys } = options;
|
|
50
|
+
if (!exchangeBodyKeys) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
const body = {};
|
|
54
|
+
exchangeBodyKeys.filter((item) => item.enabled).forEach((item) => {
|
|
55
|
+
const name = item.paramName || item.optionsKey;
|
|
56
|
+
body[name] = options[item.optionsKey];
|
|
57
|
+
});
|
|
58
|
+
return body;
|
|
59
|
+
}
|
|
60
|
+
mapField(userInfo) {
|
|
61
|
+
const { fieldMap } = this.getOptions();
|
|
62
|
+
if (!fieldMap) {
|
|
63
|
+
return userInfo;
|
|
64
|
+
}
|
|
65
|
+
fieldMap.forEach((item) => {
|
|
66
|
+
const { source, target } = item;
|
|
67
|
+
if (userInfo[source]) {
|
|
68
|
+
userInfo[target] = userInfo[source];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return userInfo;
|
|
72
|
+
}
|
|
73
|
+
async createOIDCClient() {
|
|
74
|
+
const { issuer, clientId, clientSecret, idTokenSignedResponseAlg } = this.getOptions();
|
|
75
|
+
const oidc = await import_openid_client.Issuer.discover(issuer);
|
|
76
|
+
return new oidc.Client({
|
|
77
|
+
client_id: clientId,
|
|
78
|
+
client_secret: clientSecret,
|
|
79
|
+
id_token_signed_response_alg: idTokenSignedResponseAlg || "RS256"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async validate() {
|
|
83
|
+
var _a;
|
|
84
|
+
const ctx = this.ctx;
|
|
85
|
+
const { params: values } = ctx.action;
|
|
86
|
+
const { userInfoMethod = "GET", accessTokenVia = "header", stateToken } = this.getOptions();
|
|
87
|
+
const token = stateToken || ctx.cookies.get(import_constants.cookieName);
|
|
88
|
+
const search = new URLSearchParams(decodeURIComponent(values.state));
|
|
89
|
+
if (search.get("token") !== token) {
|
|
90
|
+
ctx.logger.error("tachybase_oidc state mismatch", { method: "validate" });
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const client = await this.createOIDCClient();
|
|
94
|
+
const tokens = await client.callback(
|
|
95
|
+
this.getRedirectUri(),
|
|
96
|
+
{
|
|
97
|
+
code: values.code,
|
|
98
|
+
iss: values.iss
|
|
99
|
+
},
|
|
100
|
+
{},
|
|
101
|
+
{ exchangeBody: this.getExchangeBody() }
|
|
102
|
+
);
|
|
103
|
+
const userInfo = await client.userinfo(tokens, {
|
|
104
|
+
method: userInfoMethod,
|
|
105
|
+
via: accessTokenVia !== "query" ? accessTokenVia : "header",
|
|
106
|
+
params: accessTokenVia === "query" ? {
|
|
107
|
+
access_token: tokens.access_token
|
|
108
|
+
} : {}
|
|
109
|
+
});
|
|
110
|
+
const mappedUserInfo = this.mapField(userInfo);
|
|
111
|
+
const { nickname, username, name, sub, email, phone } = mappedUserInfo;
|
|
112
|
+
const authenticator = this.authenticator;
|
|
113
|
+
let user = await authenticator.findUser(sub);
|
|
114
|
+
if (user) {
|
|
115
|
+
return user;
|
|
116
|
+
}
|
|
117
|
+
const { userBindField = "email" } = this.getOptions();
|
|
118
|
+
if (userBindField === "email" && email) {
|
|
119
|
+
user = await this.userRepository.findOne({
|
|
120
|
+
filter: { email }
|
|
121
|
+
});
|
|
122
|
+
} else if (userBindField === "username" && username) {
|
|
123
|
+
user = await this.userRepository.findOne({
|
|
124
|
+
filter: { username }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (user) {
|
|
128
|
+
await authenticator.addUser(user.id, {
|
|
129
|
+
through: {
|
|
130
|
+
uuid: sub
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return user;
|
|
134
|
+
}
|
|
135
|
+
const { autoSignup } = ((_a = this.options) == null ? void 0 : _a.public) || {};
|
|
136
|
+
if (!autoSignup) {
|
|
137
|
+
throw new Error("User not found");
|
|
138
|
+
}
|
|
139
|
+
if (username && !this.validateUsername(username)) {
|
|
140
|
+
throw new Error(`Username must be 2-16 characters in length (excluding @.<>"'/)`);
|
|
141
|
+
}
|
|
142
|
+
return await authenticator.newUser(sub, {
|
|
143
|
+
username: username ?? null,
|
|
144
|
+
nickname: nickname || name || username || sub,
|
|
145
|
+
email: email ?? null,
|
|
146
|
+
phone: phone ?? null
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
Model,
|
|
153
|
+
OIDCAuth
|
|
154
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@tachybase/server';
|
|
2
|
+
export declare class OidcPlugin extends Plugin {
|
|
3
|
+
afterAdd(): void;
|
|
4
|
+
beforeLoad(): void;
|
|
5
|
+
load(): Promise<void>;
|
|
6
|
+
install(options?: InstallOptions): Promise<void>;
|
|
7
|
+
afterEnable(): Promise<void>;
|
|
8
|
+
afterDisable(): Promise<void>;
|
|
9
|
+
remove(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export default OidcPlugin;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var plugin_exports = {};
|
|
19
|
+
__export(plugin_exports, {
|
|
20
|
+
OidcPlugin: () => OidcPlugin,
|
|
21
|
+
default: () => plugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_server = require("@tachybase/server");
|
|
26
|
+
var import_constants = require("../constants");
|
|
27
|
+
var import_getAuthUrl = require("./actions/getAuthUrl");
|
|
28
|
+
var import_redirect = require("./actions/redirect");
|
|
29
|
+
var import_oidc_auth = require("./oidc-auth");
|
|
30
|
+
class OidcPlugin extends import_server.Plugin {
|
|
31
|
+
afterAdd() {
|
|
32
|
+
}
|
|
33
|
+
beforeLoad() {
|
|
34
|
+
}
|
|
35
|
+
async load() {
|
|
36
|
+
this.db.addMigrations({
|
|
37
|
+
namespace: "auth",
|
|
38
|
+
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
39
|
+
context: {
|
|
40
|
+
plugin: this
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.app.authManager.registerTypes(import_constants.authType, {
|
|
44
|
+
auth: import_oidc_auth.OIDCAuth
|
|
45
|
+
});
|
|
46
|
+
this.app.resourcer.define({
|
|
47
|
+
name: "oidc",
|
|
48
|
+
actions: {
|
|
49
|
+
getAuthUrl: import_getAuthUrl.getAuthUrl,
|
|
50
|
+
redirect: import_redirect.redirect
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.app.acl.allow("oidc", "*", "public");
|
|
54
|
+
import_server.Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
|
|
55
|
+
const { req } = ctx;
|
|
56
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
57
|
+
const params = url.searchParams;
|
|
58
|
+
const state = params.get("state");
|
|
59
|
+
if (!state) {
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
const search = new URLSearchParams(state);
|
|
63
|
+
const appName = search.get("app");
|
|
64
|
+
if (appName) {
|
|
65
|
+
ctx.resolvedAppName = appName;
|
|
66
|
+
}
|
|
67
|
+
await next();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async install(options) {
|
|
71
|
+
}
|
|
72
|
+
async afterEnable() {
|
|
73
|
+
}
|
|
74
|
+
async afterDisable() {
|
|
75
|
+
}
|
|
76
|
+
async remove() {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var plugin_default = OidcPlugin;
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
OidcPlugin
|
|
83
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
info: {
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
paths: {
|
|
6
|
+
'/oidc:getAuthUrl': {
|
|
7
|
+
security: any[];
|
|
8
|
+
get: {
|
|
9
|
+
description: string;
|
|
10
|
+
tags: string[];
|
|
11
|
+
parameters: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
in: string;
|
|
15
|
+
schema: {
|
|
16
|
+
type: string;
|
|
17
|
+
};
|
|
18
|
+
required: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
responses: {
|
|
21
|
+
200: {
|
|
22
|
+
description: string;
|
|
23
|
+
content: {
|
|
24
|
+
'application/json': {
|
|
25
|
+
schema: {
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
'/auth:signIn': {
|
|
35
|
+
security: any[];
|
|
36
|
+
post: {
|
|
37
|
+
description: string;
|
|
38
|
+
tags: string[];
|
|
39
|
+
parameters: {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
in: string;
|
|
43
|
+
schema: {
|
|
44
|
+
type: string;
|
|
45
|
+
};
|
|
46
|
+
required: boolean;
|
|
47
|
+
}[];
|
|
48
|
+
requestBody: {
|
|
49
|
+
content: {
|
|
50
|
+
'application/json': {
|
|
51
|
+
schema: {
|
|
52
|
+
type: string;
|
|
53
|
+
properties: {
|
|
54
|
+
code: {
|
|
55
|
+
type: string;
|
|
56
|
+
};
|
|
57
|
+
state: {
|
|
58
|
+
type: string;
|
|
59
|
+
};
|
|
60
|
+
iss: {
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
responses: {
|
|
69
|
+
200: {
|
|
70
|
+
description: string;
|
|
71
|
+
content: {
|
|
72
|
+
'application/json': {
|
|
73
|
+
schema: {
|
|
74
|
+
type: string;
|
|
75
|
+
properties: {
|
|
76
|
+
token: {
|
|
77
|
+
type: string;
|
|
78
|
+
};
|
|
79
|
+
user: {
|
|
80
|
+
type: string;
|
|
81
|
+
description: string;
|
|
82
|
+
properties: {
|
|
83
|
+
id: {
|
|
84
|
+
type: string;
|
|
85
|
+
description: string;
|
|
86
|
+
};
|
|
87
|
+
nickname: {
|
|
88
|
+
type: string;
|
|
89
|
+
description: string;
|
|
90
|
+
};
|
|
91
|
+
email: {
|
|
92
|
+
type: string;
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
phone: {
|
|
96
|
+
type: string;
|
|
97
|
+
description: string;
|
|
98
|
+
};
|
|
99
|
+
appLang: {
|
|
100
|
+
type: string;
|
|
101
|
+
description: string;
|
|
102
|
+
};
|
|
103
|
+
systemSettings: {
|
|
104
|
+
type: string;
|
|
105
|
+
description: string;
|
|
106
|
+
properties: {
|
|
107
|
+
theme: {
|
|
108
|
+
type: string;
|
|
109
|
+
description: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
createdAt: {
|
|
114
|
+
type: string;
|
|
115
|
+
format: string;
|
|
116
|
+
description: string;
|
|
117
|
+
};
|
|
118
|
+
updatedAt: {
|
|
119
|
+
type: string;
|
|
120
|
+
format: string;
|
|
121
|
+
description: string;
|
|
122
|
+
};
|
|
123
|
+
createdById: {
|
|
124
|
+
type: string;
|
|
125
|
+
description: string;
|
|
126
|
+
};
|
|
127
|
+
updatedById: {
|
|
128
|
+
type: string;
|
|
129
|
+
description: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
export default _default;
|