@things-factory/auth-base 10.1.208 → 10.1.213
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/dist-server/service/access-request/index.d.ts +1 -1
- package/dist-server/service/audit/index.d.ts +1 -1
- package/dist-server/service/domain-link/index.d.ts +1 -1
- package/dist-server/service/domain-owner/index.d.ts +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/role-template/index.d.ts +1 -1
- package/dist-server/service/web-auth-credential/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/translations/ko.json +3 -3
- package/dist-server/middlewares/webauthn-middleware.d.ts +0 -1
- package/dist-server/middlewares/webauthn-middleware.js +0 -103
- package/dist-server/middlewares/webauthn-middleware.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/auth-base",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.213",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"passport-jwt": "^4.0.0",
|
|
51
51
|
"passport-local": "^1.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "81f23aa18cb584c7d8185e81cca0d688f509cf8c"
|
|
54
54
|
}
|
package/translations/ko.json
CHANGED
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"privilege.allows.env-var.query": "서버 환경 변수의 이름과 값을 볼 수 있습니다.",
|
|
89
89
|
"privilege.allows.equipment-state.mutation": "설비 상태를 바꾸고 멈춘 사유를 남길 수 있습니다.",
|
|
90
90
|
"privilege.allows.equipment-state.query": "설비가 돌고 있는지 멈췄는지 볼 수 있습니다.",
|
|
91
|
-
"privilege.allows.figure.mutation": "
|
|
92
|
-
"privilege.allows.figure.query": "
|
|
91
|
+
"privilege.allows.figure.mutation": "피규어를 만들고 수정할 수 있습니다.",
|
|
92
|
+
"privilege.allows.figure.query": "피규어와 그 부품을 볼 수 있습니다.",
|
|
93
93
|
"privilege.allows.inspection.mutation": "검사 결과를 올리고 합부를 판단할 수 있습니다.",
|
|
94
94
|
"privilege.allows.inspection.query": "검사 기준과 검사 결과를 볼 수 있습니다.",
|
|
95
95
|
"privilege.allows.job-order.mutation": "작업지시를 발행·수정하고 종료할 수 있습니다.",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"privilege.category.employee": "임직원",
|
|
172
172
|
"privilege.category.env-var": "환경 변수",
|
|
173
173
|
"privilege.category.equipment-state": "설비 상태",
|
|
174
|
-
"privilege.category.figure": "
|
|
174
|
+
"privilege.category.figure": "피규어",
|
|
175
175
|
"privilege.category.inspection": "검사",
|
|
176
176
|
"privilege.category.job-order": "작업 지시",
|
|
177
177
|
"privilege.category.kpi": "성과 지표",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createWebAuthnMiddleware(strategy: 'webauthn-register' | 'webauthn-login'): (context: any, next: any) => Promise<any>;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWebAuthnMiddleware = createWebAuthnMiddleware;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const koa_passport_1 = tslib_1.__importDefault(require("koa-passport"));
|
|
6
|
-
const passport_custom_1 = require("passport-custom");
|
|
7
|
-
const shell_1 = require("@things-factory/shell");
|
|
8
|
-
const auth_error_js_1 = require("../errors/auth-error.js");
|
|
9
|
-
const web_auth_credential_js_1 = require("../service/web-auth-credential/web-auth-credential.js");
|
|
10
|
-
const server_1 = require("@simplewebauthn/server");
|
|
11
|
-
koa_passport_1.default.use('webauthn-register', new passport_custom_1.Strategy(async (context, done) => {
|
|
12
|
-
const { body, session, user, hostname, origin } = context;
|
|
13
|
-
const challenge = session.challenge;
|
|
14
|
-
const verification = await (0, server_1.verifyRegistrationResponse)({
|
|
15
|
-
response: body,
|
|
16
|
-
expectedChallenge: challenge,
|
|
17
|
-
expectedOrigin: origin,
|
|
18
|
-
expectedRPID: hostname,
|
|
19
|
-
expectedType: 'webauthn.create',
|
|
20
|
-
requireUserVerification: false
|
|
21
|
-
});
|
|
22
|
-
if (verification.verified) {
|
|
23
|
-
const { registrationInfo } = verification;
|
|
24
|
-
const publicKey = Buffer.from(registrationInfo.credential.publicKey).toString('base64');
|
|
25
|
-
if (!registrationInfo) {
|
|
26
|
-
return done(null, false);
|
|
27
|
-
}
|
|
28
|
-
if (user) {
|
|
29
|
-
const webAuthRepository = (0, shell_1.getRepository)(web_auth_credential_js_1.WebAuthCredential);
|
|
30
|
-
await webAuthRepository.save({
|
|
31
|
-
user,
|
|
32
|
-
credentialId: registrationInfo.credential.id,
|
|
33
|
-
publicKey,
|
|
34
|
-
counter: registrationInfo.credential.counter,
|
|
35
|
-
creator: user,
|
|
36
|
-
updater: user
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return done(null, user);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return done(null, false);
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
koa_passport_1.default.use('webauthn-login', new passport_custom_1.Strategy(async (context, done) => {
|
|
46
|
-
try {
|
|
47
|
-
const { body, session, origin, hostname } = context;
|
|
48
|
-
const challenge = session.challenge;
|
|
49
|
-
const assertionResponse = body;
|
|
50
|
-
const credential = await (0, shell_1.getRepository)(web_auth_credential_js_1.WebAuthCredential).findOne({
|
|
51
|
-
where: {
|
|
52
|
-
credentialId: assertionResponse.id
|
|
53
|
-
},
|
|
54
|
-
relations: ['user']
|
|
55
|
-
});
|
|
56
|
-
if (!credential) {
|
|
57
|
-
return done(null, false);
|
|
58
|
-
}
|
|
59
|
-
const verification = await (0, server_1.verifyAuthenticationResponse)({
|
|
60
|
-
response: body,
|
|
61
|
-
expectedChallenge: challenge,
|
|
62
|
-
expectedOrigin: origin,
|
|
63
|
-
expectedRPID: hostname,
|
|
64
|
-
requireUserVerification: false,
|
|
65
|
-
credential: {
|
|
66
|
-
id: credential.credentialId,
|
|
67
|
-
publicKey: new Uint8Array(Buffer.from(credential.publicKey, 'base64')),
|
|
68
|
-
counter: credential.counter
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
if (verification.verified) {
|
|
72
|
-
const { authenticationInfo } = verification;
|
|
73
|
-
credential.counter = authenticationInfo.newCounter;
|
|
74
|
-
await (0, shell_1.getRepository)(web_auth_credential_js_1.WebAuthCredential).save(credential);
|
|
75
|
-
const user = credential.user;
|
|
76
|
-
return done(null, user);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return done(verification, false);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return done(error, false);
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
function createWebAuthnMiddleware(strategy) {
|
|
87
|
-
return async function webAuthnMiddleware(context, next) {
|
|
88
|
-
return koa_passport_1.default.authenticate(strategy, { session: true, failureMessage: true, failWithError: true }, async (err, user) => {
|
|
89
|
-
if (err || !user) {
|
|
90
|
-
throw new auth_error_js_1.AuthError({
|
|
91
|
-
errorCode: auth_error_js_1.AuthError.ERROR_CODES.AUTHN_VERIFICATION_FAILED,
|
|
92
|
-
detail: err
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
context.state.user = user;
|
|
97
|
-
context.body = { user, verified: true };
|
|
98
|
-
}
|
|
99
|
-
await next();
|
|
100
|
-
})(context, next);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=webauthn-middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webauthn-middleware.js","sourceRoot":"","sources":["../../server/middlewares/webauthn-middleware.ts"],"names":[],"mappings":";;AA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AAC,CAAA;AACH,CAAC","sourcesContent":["import passport from 'koa-passport'\nimport { Strategy as CustomStrategy } from 'passport-custom'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { AuthError } from '../errors/auth-error.js'\n\nimport { WebAuthCredential } from '../service/web-auth-credential/web-auth-credential.js'\nimport {\n AuthenticatorAssertionResponse,\n verifyRegistrationResponse,\n verifyAuthenticationResponse\n} from '@simplewebauthn/server'\n\npassport.use(\n 'webauthn-register',\n new CustomStrategy(async (context, done) => {\n const { body, session, user, hostname, origin } = context as any\n\n const challenge = session.challenge\n\n const verification = await verifyRegistrationResponse({\n response: body,\n expectedChallenge: challenge,\n expectedOrigin: origin,\n expectedRPID: hostname,\n expectedType: 'webauthn.create',\n requireUserVerification: false\n })\n\n if (verification.verified) {\n const { registrationInfo } = verification\n const publicKey = Buffer.from(registrationInfo.credential.publicKey).toString('base64')\n if (!registrationInfo) {\n return done(null, false)\n }\n if (user) {\n const webAuthRepository = getRepository(WebAuthCredential)\n await webAuthRepository.save({\n user,\n credentialId: registrationInfo.credential.id,\n publicKey,\n counter: registrationInfo.credential.counter,\n creator: user,\n updater: user\n })\n }\n\n return done(null, user)\n } else {\n return done(null, false)\n }\n })\n)\n\npassport.use(\n 'webauthn-login',\n new CustomStrategy(async (context, done) => {\n try {\n const { body, session, origin, hostname } = context as any\n\n const challenge = session.challenge\n\n const assertionResponse = body as {\n id: string\n response: AuthenticatorAssertionResponse\n }\n\n const credential = await getRepository(WebAuthCredential).findOne({\n where: {\n credentialId: assertionResponse.id\n },\n relations: ['user']\n })\n\n if (!credential) {\n return done(null, false)\n }\n\n const verification = await verifyAuthenticationResponse({\n response: body,\n expectedChallenge: challenge,\n expectedOrigin: origin,\n expectedRPID: hostname,\n requireUserVerification: false,\n credential: {\n id: credential.credentialId,\n publicKey: new Uint8Array(Buffer.from(credential.publicKey, 'base64')),\n counter: credential.counter\n }\n })\n\n if (verification.verified) {\n const { authenticationInfo } = verification\n credential.counter = authenticationInfo.newCounter\n await getRepository(WebAuthCredential).save(credential)\n\n const user = credential.user\n return done(null, user)\n } else {\n return done(verification, false)\n }\n } catch (error) {\n return done(error, false)\n }\n })\n)\n\nexport function createWebAuthnMiddleware(strategy: 'webauthn-register' | 'webauthn-login') {\n return async function webAuthnMiddleware(context, next) {\n return passport.authenticate(\n strategy,\n { session: true, failureMessage: true, failWithError: true },\n async (err, user) => {\n if (err || !user) {\n throw new AuthError({\n errorCode: AuthError.ERROR_CODES.AUTHN_VERIFICATION_FAILED,\n detail: err\n })\n } else {\n context.state.user = user\n\n context.body = { user, verified: true }\n }\n\n await next()\n }\n )(context, next)\n }\n}\n"]}
|