@things-factory/auth-base 6.1.186 → 6.1.191

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.
Files changed (30) hide show
  1. package/dist-client/tsconfig.tsbuildinfo +1 -1
  2. package/dist-server/index.d.ts +1 -0
  3. package/dist-server/index.js +1 -0
  4. package/dist-server/index.js.map +1 -1
  5. package/dist-server/service/auth-provider/auth-provider-mutation.js +3 -3
  6. package/dist-server/service/auth-provider/auth-provider-mutation.js.map +1 -1
  7. package/dist-server/service/auth-provider/auth-provider-query.d.ts +2 -0
  8. package/dist-server/service/auth-provider/auth-provider-query.js +34 -0
  9. package/dist-server/service/auth-provider/auth-provider-query.js.map +1 -1
  10. package/dist-server/service/auth-provider/auth-provider-type.d.ts +2 -0
  11. package/dist-server/service/auth-provider/auth-provider-type.js +8 -0
  12. package/dist-server/service/auth-provider/auth-provider-type.js.map +1 -1
  13. package/dist-server/service/auth-provider/auth-provider.d.ts +1 -0
  14. package/dist-server/service/auth-provider/auth-provider.js +7 -1
  15. package/dist-server/service/auth-provider/auth-provider.js.map +1 -1
  16. package/dist-server/tsconfig.tsbuildinfo +1 -1
  17. package/dist-server/utils/encrypt-state.d.ts +2 -0
  18. package/dist-server/utils/encrypt-state.js +24 -0
  19. package/dist-server/utils/encrypt-state.js.map +1 -0
  20. package/dist-server/utils/get-aes-256-key.d.ts +1 -0
  21. package/dist-server/utils/get-aes-256-key.js +15 -0
  22. package/dist-server/utils/get-aes-256-key.js.map +1 -0
  23. package/package.json +5 -5
  24. package/server/index.ts +1 -0
  25. package/server/service/auth-provider/auth-provider-mutation.ts +3 -3
  26. package/server/service/auth-provider/auth-provider-query.ts +28 -0
  27. package/server/service/auth-provider/auth-provider-type.ts +6 -0
  28. package/server/service/auth-provider/auth-provider.ts +7 -2
  29. package/server/utils/encrypt-state.ts +22 -0
  30. package/server/utils/get-aes-256-key.ts +13 -0
@@ -0,0 +1,2 @@
1
+ export declare function encryptState(text: string): string;
2
+ export declare function decryptState(text: string): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decryptState = exports.encryptState = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
6
+ /* only for short-term life state encryption */
7
+ const KEY = crypto_1.default.randomBytes(32);
8
+ function encryptState(text) {
9
+ const iv = crypto_1.default.randomBytes(16);
10
+ const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(KEY), iv);
11
+ const encrypted = cipher.update(text);
12
+ return iv.toString('hex') + ':' + Buffer.concat([encrypted, cipher.final()]).toString('hex');
13
+ }
14
+ exports.encryptState = encryptState;
15
+ function decryptState(text) {
16
+ const textParts = text.split(':');
17
+ const iv = Buffer.from(textParts.shift(), 'hex');
18
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex');
19
+ const decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(KEY), iv);
20
+ const decrypted = decipher.update(encryptedText);
21
+ return Buffer.concat([decrypted, decipher.final()]).toString();
22
+ }
23
+ exports.decryptState = decryptState;
24
+ //# sourceMappingURL=encrypt-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt-state.js","sourceRoot":"","sources":["../../server/utils/encrypt-state.ts"],"names":[],"mappings":";;;;AAAA,4DAA2B;AAE3B,+CAA+C;AAC/C,MAAM,GAAG,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;AAElC,SAAgB,YAAY,CAAC,IAAY;IACvC,MAAM,EAAE,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IACjC,MAAM,MAAM,GAAG,gBAAM,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IACzE,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAErC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC9F,CAAC;AAND,oCAMC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;IAChD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;IAC7D,MAAM,QAAQ,GAAG,gBAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7E,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;IAEhD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;AAChE,CAAC;AARD,oCAQC","sourcesContent":["import crypto from 'crypto'\n\n/* only for short-term life state encryption */\nconst KEY = crypto.randomBytes(32)\n\nexport function encryptState(text: string) {\n const iv = crypto.randomBytes(16)\n const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(KEY), iv)\n const encrypted = cipher.update(text)\n\n return iv.toString('hex') + ':' + Buffer.concat([encrypted, cipher.final()]).toString('hex')\n}\n\nexport function decryptState(text: string) {\n const textParts = text.split(':')\n const iv = Buffer.from(textParts.shift(), 'hex')\n const encryptedText = Buffer.from(textParts.join(':'), 'hex')\n const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(KEY), iv)\n const decrypted = decipher.update(encryptedText)\n\n return Buffer.concat([decrypted, decipher.final()]).toString()\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const AES_256_KEY: any;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AES_256_KEY = void 0;
4
+ const env_1 = require("@things-factory/env");
5
+ var _AES_256_KEY = env_1.config.get('AES_256_KEY');
6
+ if (!_AES_256_KEY) {
7
+ if (process.env.NODE_ENV == 'production') {
8
+ throw new TypeError('AES_256_KEY not configured.');
9
+ }
10
+ else {
11
+ _AES_256_KEY = 'V6g5oHJZb7KcYzIyL6cM95XvIDouon5b';
12
+ }
13
+ }
14
+ exports.AES_256_KEY = _AES_256_KEY;
15
+ //# sourceMappingURL=get-aes-256-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-aes-256-key.js","sourceRoot":"","sources":["../../server/utils/get-aes-256-key.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,IAAI,YAAY,GAAG,YAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;AAE5C,IAAI,CAAC,YAAY,EAAE;IACjB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY,EAAE;QACxC,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;KACnD;SAAM;QACL,YAAY,GAAG,kCAAkC,CAAA;KAClD;CACF;AAEY,QAAA,WAAW,GAAG,YAAY,CAAA","sourcesContent":["import { config } from '@things-factory/env'\n\nvar _AES_256_KEY = config.get('AES_256_KEY')\n\nif (!_AES_256_KEY) {\n if (process.env.NODE_ENV == 'production') {\n throw new TypeError('AES_256_KEY not configured.')\n } else {\n _AES_256_KEY = 'V6g5oHJZb7KcYzIyL6cM95XvIDouon5b'\n }\n}\n\nexport const AES_256_KEY = _AES_256_KEY\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-base",
3
- "version": "6.1.186",
3
+ "version": "6.1.191",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -30,10 +30,10 @@
30
30
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
31
31
  },
32
32
  "dependencies": {
33
- "@things-factory/email-base": "^6.1.186",
33
+ "@things-factory/email-base": "^6.1.191",
34
34
  "@things-factory/env": "^6.1.175",
35
- "@things-factory/i18n-base": "^6.1.186",
36
- "@things-factory/shell": "^6.1.186",
35
+ "@things-factory/i18n-base": "^6.1.191",
36
+ "@things-factory/shell": "^6.1.191",
37
37
  "@things-factory/utils": "^6.1.186",
38
38
  "jsonwebtoken": "^9.0.0",
39
39
  "koa-passport": "^6.0.0",
@@ -42,5 +42,5 @@
42
42
  "passport-jwt": "^4.0.0",
43
43
  "passport-local": "^1.0.0"
44
44
  },
45
- "gitHead": "ddf508496cdd7d4b9d0e020703a2f7a586a42ec5"
45
+ "gitHead": "b6dfc909644710c546e38bfc0c49c3d72d528de1"
46
46
  }
package/server/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from './utils/get-user-domains'
15
15
  export * from './utils/get-secret'
16
16
  export * from './utils/check-user-belongs-domain'
17
17
  export * from './utils/access-token-cookie'
18
+ export * from './utils/encrypt-state'
18
19
  export * from './errors'
19
20
 
20
21
  export * from './types'
@@ -80,14 +80,14 @@ export class AuthProviderMutation {
80
80
 
81
81
  if (_updateRecords.length > 0) {
82
82
  for (let i = 0; i < _updateRecords.length; i++) {
83
- const newRecord = _updateRecords[i]
83
+ const updatedRecord = _updateRecords[i]
84
84
  const authProvider = await tx.getRepository(AuthProvider).findOne({
85
- where: { domain: { id: domain.id }, id: newRecord.id }
85
+ where: { domain: { id: domain.id }, id: updatedRecord.id }
86
86
  })
87
87
 
88
88
  const result = await tx.getRepository(AuthProvider).save({
89
89
  ...authProvider,
90
- ...newRecord,
90
+ ...updatedRecord,
91
91
  updater: user
92
92
  })
93
93
 
@@ -40,6 +40,34 @@ export class AuthProviderQuery {
40
40
  return { items, total }
41
41
  }
42
42
 
43
+ @FieldResolver(type => String)
44
+ clientSecret(@Root() authProvider: AuthProvider): string {
45
+ const clientSecret = authProvider.clientSecret
46
+
47
+ if (!clientSecret || clientSecret.length <= 2) {
48
+ return clientSecret // 입력 문자열의 길이가 2 이하인 경우 그대로 반환
49
+ }
50
+ const firstChar = clientSecret.charAt(0)
51
+ const lastChar = clientSecret.charAt(clientSecret.length - 1)
52
+ const maskedPart = '*'.repeat(clientSecret.length - 2)
53
+
54
+ return firstChar + maskedPart + lastChar
55
+ }
56
+
57
+ @FieldResolver(type => String)
58
+ privateKey(@Root() authProvider: AuthProvider): string {
59
+ const privateKey = authProvider.privateKey
60
+
61
+ if (!privateKey || privateKey.length <= 2) {
62
+ return privateKey // 입력 문자열의 길이가 2 이하인 경우 그대로 반환
63
+ }
64
+ const firstChar = privateKey.charAt(0)
65
+ const lastChar = privateKey.charAt(privateKey.length - 1)
66
+ const maskedPart = '*'.repeat(privateKey.length - 2)
67
+
68
+ return firstChar + maskedPart + lastChar
69
+ }
70
+
43
71
  @FieldResolver(type => Domain)
44
72
  async domain(@Root() authProvider: AuthProvider): Promise<Domain> {
45
73
  return authProvider.domainId && (await getRepository(Domain).findOneBy({ id: authProvider.domainId }))
@@ -24,6 +24,9 @@ export class NewAuthProvider {
24
24
  @Field({ nullable: true })
25
25
  clientSecret?: string
26
26
 
27
+ @Field({ nullable: true })
28
+ privateKey?: string
29
+
27
30
  @Field(type => ScalarObject, { nullable: true })
28
31
  params?: { [key: string]: any }
29
32
  }
@@ -48,6 +51,9 @@ export class AuthProviderPatch {
48
51
  @Field({ nullable: true })
49
52
  clientSecret?: string
50
53
 
54
+ @Field({ nullable: true })
55
+ privateKey?: string
56
+
51
57
  @Field(type => ScalarObject, { nullable: true })
52
58
  params?: { [key: string]: any }
53
59
 
@@ -13,7 +13,7 @@ import {
13
13
  } from 'typeorm'
14
14
  import { Directive, ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
15
15
 
16
- import { Domain, ScalarObject } from '@things-factory/shell'
16
+ import { Domain, ScalarObject, encryptTransformer } from '@things-factory/shell'
17
17
  import { User } from '../user/user'
18
18
  import { UsersAuthProviders } from '../users-auth-providers/users-auth-providers'
19
19
  import { AuthProviderParameterSpec } from './auth-provider-parameter-spec'
@@ -104,10 +104,15 @@ export class AuthProvider {
104
104
  clientId?: string
105
105
 
106
106
  @Directive('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)')
107
- @Column({ nullable: true })
107
+ @Column({ nullable: true, transformer: encryptTransformer })
108
108
  @Field({ nullable: true })
109
109
  clientSecret?: string
110
110
 
111
+ @Directive('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)')
112
+ @Column({ nullable: true, transformer: encryptTransformer })
113
+ @Field({ nullable: true })
114
+ privateKey?: string
115
+
111
116
  @Column('simple-json', { nullable: true })
112
117
  @Field(type => ScalarObject, { nullable: true })
113
118
  params?: { [key: string]: any }
@@ -0,0 +1,22 @@
1
+ import crypto from 'crypto'
2
+
3
+ /* only for short-term life state encryption */
4
+ const KEY = crypto.randomBytes(32)
5
+
6
+ export function encryptState(text: string) {
7
+ const iv = crypto.randomBytes(16)
8
+ const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(KEY), iv)
9
+ const encrypted = cipher.update(text)
10
+
11
+ return iv.toString('hex') + ':' + Buffer.concat([encrypted, cipher.final()]).toString('hex')
12
+ }
13
+
14
+ export function decryptState(text: string) {
15
+ const textParts = text.split(':')
16
+ const iv = Buffer.from(textParts.shift(), 'hex')
17
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex')
18
+ const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(KEY), iv)
19
+ const decrypted = decipher.update(encryptedText)
20
+
21
+ return Buffer.concat([decrypted, decipher.final()]).toString()
22
+ }
@@ -0,0 +1,13 @@
1
+ import { config } from '@things-factory/env'
2
+
3
+ var _AES_256_KEY = config.get('AES_256_KEY')
4
+
5
+ if (!_AES_256_KEY) {
6
+ if (process.env.NODE_ENV == 'production') {
7
+ throw new TypeError('AES_256_KEY not configured.')
8
+ } else {
9
+ _AES_256_KEY = 'V6g5oHJZb7KcYzIyL6cM95XvIDouon5b'
10
+ }
11
+ }
12
+
13
+ export const AES_256_KEY = _AES_256_KEY