@ubs-platform/users-webservice 9.4.0 → 9.6.0
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/_monaembed/@ubs-platform/users-consts/package.json +1 -1
- package/index.d.ts +6 -0
- package/index.js +6 -0
- package/index.js.map +1 -1
- package/oauth/google-oauth-provider.d.ts +4 -0
- package/oauth/google-oauth-provider.js +16 -0
- package/oauth/google-oauth-provider.js.map +1 -0
- package/oauth/oauth-provider-registry.d.ts +7 -0
- package/oauth/oauth-provider-registry.js +31 -0
- package/oauth/oauth-provider-registry.js.map +1 -0
- package/oauth/oauth-provider.d.ts +19 -0
- package/oauth/oauth-provider.js +10 -0
- package/oauth/oauth-provider.js.map +1 -0
- package/oauth/oidc-provider.d.ts +27 -0
- package/oauth/oidc-provider.js +111 -0
- package/oauth/oidc-provider.js.map +1 -0
- package/package.json +1 -1
- package/services/auth.service.d.ts +1 -0
- package/services/auth.service.js +4 -5
- package/services/auth.service.js.map +1 -1
- package/services/oauth.service.d.ts +32 -0
- package/services/oauth.service.js +278 -0
- package/services/oauth.service.js.map +1 -0
- package/users-webservice.module.js +7 -1
- package/users-webservice.module.js.map +1 -1
- package/web/oauth.controller.d.ts +14 -0
- package/web/oauth.controller.js +139 -0
- package/web/oauth.controller.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@ubs-platform/users-consts","version":"9.
|
|
1
|
+
{"name":"@ubs-platform/users-consts","version":"9.6.0","description":"","repository":{"type":"git","url":"git+https://github.com/ubs-platform/ubs-mona-mr.git"},"homepage":"https://github.com/ubs-platform/ubs-mona-mr","iksir":{"type":"LIBRARY","libraryMode":"EMBEDDED"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './local-current-user-decorator';
|
|
2
2
|
export * from './web/user.controller';
|
|
3
3
|
export * from './web/auth.controller';
|
|
4
|
+
export * from './web/oauth.controller';
|
|
4
5
|
export * from './web/user-admin.controller';
|
|
5
6
|
export * from './web/password-reset.controller';
|
|
6
7
|
export * from './web/entity-ownership.controller';
|
|
@@ -13,6 +14,11 @@ export * from './services/user.service';
|
|
|
13
14
|
export * from './services/user-common.service';
|
|
14
15
|
export * from './services/user-register.service';
|
|
15
16
|
export * from './services/auth.service';
|
|
17
|
+
export * from './services/oauth.service';
|
|
18
|
+
export * from './oauth/oauth-provider';
|
|
19
|
+
export * from './oauth/oidc-provider';
|
|
20
|
+
export * from './oauth/google-oauth-provider';
|
|
21
|
+
export * from './oauth/oauth-provider-registry';
|
|
16
22
|
export * from './services/email-change-request.service';
|
|
17
23
|
export * from './services/password-reset.service';
|
|
18
24
|
export * from './services/email.service';
|
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./local-current-user-decorator"), exports);
|
|
18
18
|
__exportStar(require("./web/user.controller"), exports);
|
|
19
19
|
__exportStar(require("./web/auth.controller"), exports);
|
|
20
|
+
__exportStar(require("./web/oauth.controller"), exports);
|
|
20
21
|
__exportStar(require("./web/user-admin.controller"), exports);
|
|
21
22
|
__exportStar(require("./web/password-reset.controller"), exports);
|
|
22
23
|
__exportStar(require("./web/entity-ownership.controller"), exports);
|
|
@@ -29,6 +30,11 @@ __exportStar(require("./services/user.service"), exports);
|
|
|
29
30
|
__exportStar(require("./services/user-common.service"), exports);
|
|
30
31
|
__exportStar(require("./services/user-register.service"), exports);
|
|
31
32
|
__exportStar(require("./services/auth.service"), exports);
|
|
33
|
+
__exportStar(require("./services/oauth.service"), exports);
|
|
34
|
+
__exportStar(require("./oauth/oauth-provider"), exports);
|
|
35
|
+
__exportStar(require("./oauth/oidc-provider"), exports);
|
|
36
|
+
__exportStar(require("./oauth/google-oauth-provider"), exports);
|
|
37
|
+
__exportStar(require("./oauth/oauth-provider-registry"), exports);
|
|
32
38
|
__exportStar(require("./services/email-change-request.service"), exports);
|
|
33
39
|
__exportStar(require("./services/password-reset.service"), exports);
|
|
34
40
|
__exportStar(require("./services/email.service"), exports);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,wDAAsC;AACtC,wDAAsC;AACtC,8DAA4C;AAC5C,kEAAgD;AAChD,oEAAkD;AAClD,qEAAmD;AACnD,qEAAmD;AACnD,uFAAqE;AACrE,0EAAwD;AACxD,iFAA+D;AAC/D,0DAAwC;AACxC,iEAA+C;AAC/C,mEAAiD;AACjD,0DAAwC;AACxC,0EAAwD;AACxD,oEAAkD;AAClD,2DAAyC;AACzC,sEAAoD;AACpD,4EAA0D;AAC1D,0DAAwC;AACxC,kEAAgD;AAChD,mEAAiD;AACjD,yEAAuD;AACvD,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,wDAAsC;AACtC,wDAAsC;AACtC,yDAAuC;AACvC,8DAA4C;AAC5C,kEAAgD;AAChD,oEAAkD;AAClD,qEAAmD;AACnD,qEAAmD;AACnD,uFAAqE;AACrE,0EAAwD;AACxD,iFAA+D;AAC/D,0DAAwC;AACxC,iEAA+C;AAC/C,mEAAiD;AACjD,0DAAwC;AACxC,2DAAyC;AACzC,yDAAuC;AACvC,wDAAsC;AACtC,gEAA8C;AAC9C,kEAAgD;AAChD,0EAAwD;AACxD,oEAAkD;AAClD,2DAAyC;AACzC,sEAAoD;AACpD,4EAA0D;AAC1D,0DAAwC;AACxC,kEAAgD;AAChD,mEAAiD;AACjD,yEAAuD;AACvD,4DAA0C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleOAuthProvider = void 0;
|
|
4
|
+
const oidc_provider_1 = require("./oidc-provider");
|
|
5
|
+
class GoogleOAuthProvider extends oidc_provider_1.OidcProvider {
|
|
6
|
+
constructor(env = process.env) {
|
|
7
|
+
super({
|
|
8
|
+
name: 'google',
|
|
9
|
+
clientIds: (0, oidc_provider_1.envList)(env['U_USERS_OAUTH_GOOGLE_CLIENT_ID']),
|
|
10
|
+
issuers: ['https://accounts.google.com', 'accounts.google.com'],
|
|
11
|
+
jwksUri: 'https://www.googleapis.com/oauth2/v3/certs',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.GoogleOAuthProvider = GoogleOAuthProvider;
|
|
16
|
+
//# sourceMappingURL=google-oauth-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-oauth-provider.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/oauth/google-oauth-provider.ts"],"names":[],"mappings":";;;AAAA,mDAAwD;AAMxD,MAAa,mBAAoB,SAAQ,4BAAY;IACjD,YAAY,MAAyB,OAAO,CAAC,GAAG;QAC5C,KAAK,CAAC;YACF,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAA,uBAAO,EAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;YACzD,OAAO,EAAE,CAAC,6BAA6B,EAAE,qBAAqB,CAAC;YAC/D,OAAO,EAAE,4CAA4C;SACxD,CAAC,CAAC;IACP,CAAC;CACJ;AATD,kDASC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OAuthProviderRegistry = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const google_oauth_provider_1 = require("./google-oauth-provider");
|
|
15
|
+
let OAuthProviderRegistry = class OAuthProviderRegistry {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.providers = [new google_oauth_provider_1.GoogleOAuthProvider()].filter((p) => p.isConfigured());
|
|
18
|
+
}
|
|
19
|
+
list() {
|
|
20
|
+
return this.providers;
|
|
21
|
+
}
|
|
22
|
+
find(name) {
|
|
23
|
+
return this.providers.find((p) => p.name === name);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.OAuthProviderRegistry = OAuthProviderRegistry;
|
|
27
|
+
exports.OAuthProviderRegistry = OAuthProviderRegistry = __decorate([
|
|
28
|
+
(0, common_1.Injectable)(),
|
|
29
|
+
__metadata("design:paramtypes", [])
|
|
30
|
+
], OAuthProviderRegistry);
|
|
31
|
+
//# sourceMappingURL=oauth-provider-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider-registry.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/oauth/oauth-provider-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,mEAA8D;AAKvD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAG9B;QACI,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,2CAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,CAAC,CAAC,YAAY,EAAE,CACnB,CAAC;IACN,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC,IAAY;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAhBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;;GACA,qBAAqB,CAgBjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OAuthProviderInfoDTO } from '@ubs-platform/users-common';
|
|
2
|
+
export interface OAuthIdentity {
|
|
3
|
+
provider: string;
|
|
4
|
+
subject: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
emailVerified: boolean;
|
|
7
|
+
name?: string;
|
|
8
|
+
surname?: string;
|
|
9
|
+
picture?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface OAuthVerifyInput {
|
|
12
|
+
credential: string;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class OAuthProvider {
|
|
15
|
+
abstract readonly name: string;
|
|
16
|
+
abstract isConfigured(): boolean;
|
|
17
|
+
abstract verify(input: OAuthVerifyInput): Promise<OAuthIdentity>;
|
|
18
|
+
publicInfo(): OAuthProviderInfoDTO;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthProvider = void 0;
|
|
4
|
+
class OAuthProvider {
|
|
5
|
+
publicInfo() {
|
|
6
|
+
return { name: this.name };
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.OAuthProvider = OAuthProvider;
|
|
10
|
+
//# sourceMappingURL=oauth-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/oauth/oauth-provider.ts"],"names":[],"mappings":";;;AAuBA,MAAsB,aAAa;IAS/B,UAAU;QACN,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACJ;AAZD,sCAYC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OAuthIdentity, OAuthProvider, OAuthVerifyInput } from './oauth-provider';
|
|
2
|
+
export interface OidcProviderConfig {
|
|
3
|
+
name: string;
|
|
4
|
+
clientIds: string[];
|
|
5
|
+
issuers: string[];
|
|
6
|
+
jwksUri: string;
|
|
7
|
+
algorithms?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare class OidcProvider extends OAuthProvider {
|
|
10
|
+
protected readonly config: OidcProviderConfig;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
private readonly jwt;
|
|
13
|
+
private keys;
|
|
14
|
+
private keysExpireAt;
|
|
15
|
+
private lastFetchAt;
|
|
16
|
+
constructor(config: OidcProviderConfig);
|
|
17
|
+
isConfigured(): boolean;
|
|
18
|
+
publicInfo(): {
|
|
19
|
+
name: string;
|
|
20
|
+
clientId: string;
|
|
21
|
+
};
|
|
22
|
+
verify(input: OAuthVerifyInput): Promise<OAuthIdentity>;
|
|
23
|
+
protected toIdentity(claims: Record<string, unknown>): OAuthIdentity;
|
|
24
|
+
private findKey;
|
|
25
|
+
private refreshKeys;
|
|
26
|
+
}
|
|
27
|
+
export declare function envList(value: string | undefined): string[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OidcProvider = void 0;
|
|
4
|
+
exports.envList = envList;
|
|
5
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const oauth_provider_1 = require("./oauth-provider");
|
|
8
|
+
const DEFAULT_JWKS_TTL_MS = 60 * 60 * 1000;
|
|
9
|
+
const MIN_JWKS_REFRESH_INTERVAL_MS = 60 * 1000;
|
|
10
|
+
class OidcProvider extends oauth_provider_1.OAuthProvider {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super();
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.jwt = new jwt_1.JwtService();
|
|
15
|
+
this.keys = new Map();
|
|
16
|
+
this.keysExpireAt = 0;
|
|
17
|
+
this.lastFetchAt = 0;
|
|
18
|
+
this.name = config.name;
|
|
19
|
+
}
|
|
20
|
+
isConfigured() {
|
|
21
|
+
return this.config.clientIds.length > 0;
|
|
22
|
+
}
|
|
23
|
+
publicInfo() {
|
|
24
|
+
return { name: this.name, clientId: this.config.clientIds[0] };
|
|
25
|
+
}
|
|
26
|
+
async verify(input) {
|
|
27
|
+
if (!this.isConfigured()) {
|
|
28
|
+
throw new Error(`OAuth provider ${this.name} is not configured`);
|
|
29
|
+
}
|
|
30
|
+
const decoded = this.jwt.decode(input.credential, { complete: true });
|
|
31
|
+
const kid = decoded?.header?.kid;
|
|
32
|
+
if (!kid) {
|
|
33
|
+
throw new Error('Credential has no key id');
|
|
34
|
+
}
|
|
35
|
+
const publicKey = await this.findKey(kid);
|
|
36
|
+
const claims = await this.jwt.verifyAsync(input.credential, {
|
|
37
|
+
publicKey,
|
|
38
|
+
algorithms: (this.config.algorithms ?? ['RS256']),
|
|
39
|
+
issuer: this.config.issuers,
|
|
40
|
+
audience: this.config.clientIds,
|
|
41
|
+
});
|
|
42
|
+
if (typeof claims['sub'] !== 'string' || !claims['sub']) {
|
|
43
|
+
throw new Error('Credential has no subject');
|
|
44
|
+
}
|
|
45
|
+
return this.toIdentity(claims);
|
|
46
|
+
}
|
|
47
|
+
toIdentity(claims) {
|
|
48
|
+
const text = (key) => typeof claims[key] === 'string' && claims[key]
|
|
49
|
+
? claims[key]
|
|
50
|
+
: undefined;
|
|
51
|
+
return {
|
|
52
|
+
provider: this.name,
|
|
53
|
+
subject: claims['sub'],
|
|
54
|
+
email: text('email')?.toLowerCase(),
|
|
55
|
+
emailVerified: claims['email_verified'] === true ||
|
|
56
|
+
claims['email_verified'] === 'true',
|
|
57
|
+
name: text('given_name') ?? text('name'),
|
|
58
|
+
surname: text('family_name'),
|
|
59
|
+
picture: text('picture'),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async findKey(kid) {
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
const stale = now >= this.keysExpireAt;
|
|
65
|
+
const unknown = !this.keys.has(kid) &&
|
|
66
|
+
now - this.lastFetchAt >= MIN_JWKS_REFRESH_INTERVAL_MS;
|
|
67
|
+
if (stale || unknown) {
|
|
68
|
+
await this.refreshKeys();
|
|
69
|
+
}
|
|
70
|
+
const key = this.keys.get(kid);
|
|
71
|
+
if (!key) {
|
|
72
|
+
throw new Error('Credential is signed with an unknown key');
|
|
73
|
+
}
|
|
74
|
+
return key;
|
|
75
|
+
}
|
|
76
|
+
async refreshKeys() {
|
|
77
|
+
this.lastFetchAt = Date.now();
|
|
78
|
+
const response = await fetch(this.config.jwksUri);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`JWKS request failed with ${response.status}`);
|
|
81
|
+
}
|
|
82
|
+
const body = (await response.json());
|
|
83
|
+
const keys = new Map();
|
|
84
|
+
for (const jwk of body.keys ?? []) {
|
|
85
|
+
if (!jwk.kid || (jwk.use && jwk.use !== 'sig')) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const pem = (0, crypto_1.createPublicKey)({ key: jwk, format: 'jwk' })
|
|
89
|
+
.export({ type: 'spki', format: 'pem' })
|
|
90
|
+
.toString();
|
|
91
|
+
keys.set(jwk.kid, pem);
|
|
92
|
+
}
|
|
93
|
+
this.keys = keys;
|
|
94
|
+
this.keysExpireAt =
|
|
95
|
+
this.lastFetchAt +
|
|
96
|
+
(parseMaxAge(response.headers.get('cache-control')) ??
|
|
97
|
+
DEFAULT_JWKS_TTL_MS);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.OidcProvider = OidcProvider;
|
|
101
|
+
function parseMaxAge(cacheControl) {
|
|
102
|
+
const match = cacheControl?.match(/max-age=(\d+)/);
|
|
103
|
+
return match ? parseInt(match[1], 10) * 1000 : undefined;
|
|
104
|
+
}
|
|
105
|
+
function envList(value) {
|
|
106
|
+
return (value ?? '')
|
|
107
|
+
.split(',')
|
|
108
|
+
.map((item) => item.trim())
|
|
109
|
+
.filter(Boolean);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=oidc-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-provider.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/oauth/oidc-provider.ts"],"names":[],"mappings":";;;AA+IA,0BAKC;AApJD,qCAAyC;AACzC,mCAAqD;AACrD,qDAAkF;AAYlF,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,CAAC;AAM/C,MAAa,YAAa,SAAQ,8BAAa;IAU3C,YAA+B,MAA0B;QACrD,KAAK,EAAE,CAAC;QADmB,WAAM,GAAN,MAAM,CAAoB;QALxC,QAAG,GAAG,IAAI,gBAAU,EAAE,CAAC;QAChC,SAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;QACjC,iBAAY,GAAG,CAAC,CAAC;QACjB,gBAAW,GAAG,CAAC,CAAC;QAIpB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5C,CAAC;IAGD,UAAU;QACN,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CA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,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC;AAGD,SAAgB,OAAO,CAAC,KAAyB;IAC7C,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;SACf,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@ubs-platform/users-webservice","version":"9.
|
|
1
|
+
{"name":"@ubs-platform/users-webservice","version":"9.6.0","description":"","repository":{"type":"git","url":"git+https://github.com/ubs-platform/ubs-mona-mr.git"},"homepage":"https://github.com/ubs-platform/ubs-mona-mr","iksir":{"type":"LIBRARY","libraryMode":"PEER","buildSubFolder":""},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC","peerDependencies":{"@nestjs/common":"^12.0.0","@nestjs/microservices":"^12.0.0","bcrypt":"^6.0.0","@nestjs/passport":"^12.0.0","passport-jwt":"^4.0.1","@nestjs/jwt":"^12.0.0","mongoose":"^8.10.2","@nestjs/mongoose":"^12.0.0","@nestjs/schedule":"^12.0.0","@ubs-platform/cache-manager":"9.6.0","@ubs-platform/users-microservice-helper":"9.6.0","@ubs-platform/microservice-setup-util":"9.6.0","@ubs-platform/users-common":"9.6.0","@ubs-platform/users-roles":"9.6.0","@ubs-platform/crud-base-common":"9.6.0","@ubs-platform/crud-base":"9.6.0"}}
|
|
@@ -8,5 +8,6 @@ export declare class AuthService {
|
|
|
8
8
|
constructor(userService: UserService, jwtService: JwtService);
|
|
9
9
|
currentUserByJwtForFirstLogin(request: Request): Promise<import("@ubs-platform/users-common").UserDTO>;
|
|
10
10
|
authenticateUser(userLogin: UserAuth): Promise<UserAuthSuccess>;
|
|
11
|
+
issueToken(userId: any): UserAuthSuccess;
|
|
11
12
|
verifyToken(token: string): Promise<boolean>;
|
|
12
13
|
}
|
package/services/auth.service.js
CHANGED
|
@@ -36,16 +36,15 @@ let AuthService = class AuthService {
|
|
|
36
36
|
async authenticateUser(userLogin) {
|
|
37
37
|
let realUser = await this.userService.findUserWithPassword(userLogin);
|
|
38
38
|
if (realUser) {
|
|
39
|
-
|
|
40
|
-
userId: realUser.id,
|
|
41
|
-
};
|
|
42
|
-
const token = this.jwtService.sign(payload);
|
|
43
|
-
return new users_common_1.UserAuthSuccess(token);
|
|
39
|
+
return this.issueToken(realUser.id);
|
|
44
40
|
}
|
|
45
41
|
else {
|
|
46
42
|
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.AUTHENTICATION_FAIL, 'User is not found or password does not match');
|
|
47
43
|
}
|
|
48
44
|
}
|
|
45
|
+
issueToken(userId) {
|
|
46
|
+
return new users_common_1.UserAuthSuccess(this.jwtService.sign({ userId }));
|
|
47
|
+
}
|
|
49
48
|
async verifyToken(token) {
|
|
50
49
|
const verifed = await this.jwtService.verifyAsync(token);
|
|
51
50
|
return verifed != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/services/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAKoC;AACpC,2CAAmE;AACnE,qCAAyC;AACzC,iDAA6C;AAGtC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACpB,YACY,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;IAC/B,CAAC;IAEJ,KAAK,CAAC,6BAA6B,CAAC,OAAgB;QAChD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa;YACrC,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YACxB,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAE7B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,GAAI,CAAC,CAAC;QAE3D,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/B,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAClD,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACtC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAmB;QACtC,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAEtE,IAAI,QAAQ,EAAE,CAAC;YACX,
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/services/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAKoC;AACpC,2CAAmE;AACnE,qCAAyC;AACzC,iDAA6C;AAGtC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACpB,YACY,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;IAC/B,CAAC;IAEJ,KAAK,CAAC,6BAA6B,CAAC,OAAgB;QAChD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa;YACrC,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YACxB,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAE7B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,GAAI,CAAC,CAAC;QAE3D,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/B,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAClD,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACtC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAmB;QACtC,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAEtE,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,gCAAiB,CACvB,kCAAmB,CAAC,mBAAmB,EACvC,8CAA8C,CACjD,CAAC;QACN,CAAC;IACL,CAAC;IAGD,UAAU,CAAC,MAAW;QAClB,OAAO,IAAI,8BAAe,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa;QAC3B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzD,OAAO,OAAO,IAAI,IAAI,CAAC;IAC3B,CAAC;CACJ,CAAA;AA5CY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAGgB,0BAAW;QACZ,gBAAU;GAHzB,WAAW,CA4CvB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { OAuthCompleteRegistrationDTO, OAuthLinkDTO, OAuthLoginResultDTO } from '@ubs-platform/users-common';
|
|
3
|
+
import { OAuthLoginSession, User, UserOAuthLink } from '@ubs-platform/users-entity-mongo';
|
|
4
|
+
import { OAuthProviderRegistry } from '../oauth/oauth-provider-registry';
|
|
5
|
+
import { AuthService } from './auth.service';
|
|
6
|
+
import { UserService } from './user.service';
|
|
7
|
+
export declare class OAuthService {
|
|
8
|
+
private userModel;
|
|
9
|
+
private linkModel;
|
|
10
|
+
private sessionModel;
|
|
11
|
+
private providers;
|
|
12
|
+
private userService;
|
|
13
|
+
private authService;
|
|
14
|
+
constructor(userModel: Model<User>, linkModel: Model<UserOAuthLink>, sessionModel: Model<OAuthLoginSession>, providers: OAuthProviderRegistry, userService: UserService, authService: AuthService);
|
|
15
|
+
listProviders(): import("@ubs-platform/users-common").OAuthProviderInfoDTO[];
|
|
16
|
+
login(providerName: string, credential: string): Promise<OAuthLoginResultDTO>;
|
|
17
|
+
getSession(key: string): Promise<OAuthLoginResultDTO>;
|
|
18
|
+
completeRegistration(key: string, dto: OAuthCompleteRegistrationDTO): Promise<OAuthLoginResultDTO>;
|
|
19
|
+
linkWithPassword(key: string, password: string): Promise<OAuthLoginResultDTO>;
|
|
20
|
+
listLinks(userId: string): Promise<OAuthLinkDTO[]>;
|
|
21
|
+
linkToUser(userId: string, providerName: string, credential: string): Promise<OAuthLinkDTO[]>;
|
|
22
|
+
unlink(userId: string, linkId: string): Promise<OAuthLinkDTO[]>;
|
|
23
|
+
private verify;
|
|
24
|
+
private findSession;
|
|
25
|
+
private createLink;
|
|
26
|
+
private assertCanLogin;
|
|
27
|
+
private loggedIn;
|
|
28
|
+
private pending;
|
|
29
|
+
private suggestUsername;
|
|
30
|
+
private sessionNotFound;
|
|
31
|
+
private invalidCredential;
|
|
32
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OAuthService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
18
|
+
const mongoose_2 = require("mongoose");
|
|
19
|
+
const users_common_1 = require("@ubs-platform/users-common");
|
|
20
|
+
const users_entity_mongo_1 = require("@ubs-platform/users-entity-mongo");
|
|
21
|
+
const oauth_provider_registry_1 = require("../oauth/oauth-provider-registry");
|
|
22
|
+
const crypto_op_1 = require("../util/crypto-op");
|
|
23
|
+
const auth_service_1 = require("./auth.service");
|
|
24
|
+
const user_service_1 = require("./user.service");
|
|
25
|
+
const SESSION_TTL_MS = 15 * 60 * 1000;
|
|
26
|
+
const MAX_LINK_ATTEMPTS = 5;
|
|
27
|
+
let OAuthService = class OAuthService {
|
|
28
|
+
constructor(userModel, linkModel, sessionModel, providers, userService, authService) {
|
|
29
|
+
this.userModel = userModel;
|
|
30
|
+
this.linkModel = linkModel;
|
|
31
|
+
this.sessionModel = sessionModel;
|
|
32
|
+
this.providers = providers;
|
|
33
|
+
this.userService = userService;
|
|
34
|
+
this.authService = authService;
|
|
35
|
+
}
|
|
36
|
+
listProviders() {
|
|
37
|
+
return this.providers.list().map((p) => p.publicInfo());
|
|
38
|
+
}
|
|
39
|
+
async login(providerName, credential) {
|
|
40
|
+
const identity = await this.verify(providerName, credential);
|
|
41
|
+
const link = await this.linkModel.findOne({
|
|
42
|
+
provider: identity.provider,
|
|
43
|
+
subject: identity.subject,
|
|
44
|
+
});
|
|
45
|
+
if (link) {
|
|
46
|
+
const user = await this.userModel.findById(link.userId);
|
|
47
|
+
if (user) {
|
|
48
|
+
this.assertCanLogin(user);
|
|
49
|
+
link.lastLoginAt = new Date();
|
|
50
|
+
await link.save();
|
|
51
|
+
return this.loggedIn(identity.provider, user._id);
|
|
52
|
+
}
|
|
53
|
+
await link.deleteOne();
|
|
54
|
+
}
|
|
55
|
+
if (!identity.email || !identity.emailVerified) {
|
|
56
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_EMAIL_NOT_VERIFIED, 'The provider did not return a verified e-mail address.');
|
|
57
|
+
}
|
|
58
|
+
const existing = await this.userModel.findOne({
|
|
59
|
+
primaryEmail: identity.email,
|
|
60
|
+
});
|
|
61
|
+
const session = await this.sessionModel.create({
|
|
62
|
+
provider: identity.provider,
|
|
63
|
+
subject: identity.subject,
|
|
64
|
+
email: identity.email,
|
|
65
|
+
name: identity.name,
|
|
66
|
+
surname: identity.surname,
|
|
67
|
+
picture: identity.picture,
|
|
68
|
+
existingUserId: existing?._id?.toString(),
|
|
69
|
+
expireAfter: new Date(Date.now() + SESSION_TTL_MS),
|
|
70
|
+
});
|
|
71
|
+
return this.pending(session);
|
|
72
|
+
}
|
|
73
|
+
async getSession(key) {
|
|
74
|
+
return this.pending(await this.findSession(key));
|
|
75
|
+
}
|
|
76
|
+
async completeRegistration(key, dto) {
|
|
77
|
+
const session = await this.findSession(key);
|
|
78
|
+
if (session.existingUserId) {
|
|
79
|
+
throw this.sessionNotFound();
|
|
80
|
+
}
|
|
81
|
+
const username = dto?.username?.trim();
|
|
82
|
+
if (!username ||
|
|
83
|
+
/\s/.test(username) ||
|
|
84
|
+
!dto.password ||
|
|
85
|
+
!dto.name?.trim() ||
|
|
86
|
+
!dto.surname?.trim()) {
|
|
87
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.EMPTY_DATA, 'Username, password, name and surname are required; the username cannot contain spaces.');
|
|
88
|
+
}
|
|
89
|
+
const user = await this.userService.saveNewUser({
|
|
90
|
+
username,
|
|
91
|
+
password: dto.password,
|
|
92
|
+
primaryEmail: session.email,
|
|
93
|
+
name: dto.name.trim(),
|
|
94
|
+
surname: dto.surname.trim(),
|
|
95
|
+
localeCode: dto.localeCode ?? '',
|
|
96
|
+
active: true,
|
|
97
|
+
roles: [],
|
|
98
|
+
});
|
|
99
|
+
await this.createLink(user.id, session);
|
|
100
|
+
await session.deleteOne();
|
|
101
|
+
return this.loggedIn(session.provider, user.id);
|
|
102
|
+
}
|
|
103
|
+
async linkWithPassword(key, password) {
|
|
104
|
+
const session = await this.sessionModel.findOneAndUpdate({
|
|
105
|
+
_id: key,
|
|
106
|
+
existingUserId: { $exists: true },
|
|
107
|
+
expireAfter: { $gt: new Date() },
|
|
108
|
+
}, { $inc: { linkAttempts: 1 } }, { new: true });
|
|
109
|
+
if (!session) {
|
|
110
|
+
throw this.sessionNotFound();
|
|
111
|
+
}
|
|
112
|
+
if (session.linkAttempts > MAX_LINK_ATTEMPTS) {
|
|
113
|
+
await session.deleteOne();
|
|
114
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_TOO_MANY_ATTEMPTS, 'Too many wrong passwords; sign in with the provider again.');
|
|
115
|
+
}
|
|
116
|
+
const user = await this.userModel.findById(session.existingUserId);
|
|
117
|
+
const passwordMatches = !!user?.passwordEncyripted &&
|
|
118
|
+
!!password &&
|
|
119
|
+
(await crypto_op_1.CryptoOp.checkPassword(password, user.passwordEncyripted));
|
|
120
|
+
if (!user || !passwordMatches) {
|
|
121
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.AUTHENTICATION_FAIL, 'Password does not match');
|
|
122
|
+
}
|
|
123
|
+
this.assertCanLogin(user);
|
|
124
|
+
await this.createLink(user._id, session);
|
|
125
|
+
await session.deleteOne();
|
|
126
|
+
return this.loggedIn(session.provider, user._id);
|
|
127
|
+
}
|
|
128
|
+
async listLinks(userId) {
|
|
129
|
+
const links = await this.linkModel
|
|
130
|
+
.find({ userId: String(userId) })
|
|
131
|
+
.sort({ linkedAt: 1 });
|
|
132
|
+
return links.map((l) => ({
|
|
133
|
+
id: l._id.toString(),
|
|
134
|
+
provider: l.provider,
|
|
135
|
+
email: l.email,
|
|
136
|
+
linkedAt: l.linkedAt,
|
|
137
|
+
lastLoginAt: l.lastLoginAt,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
async linkToUser(userId, providerName, credential) {
|
|
141
|
+
const identity = await this.verify(providerName, credential);
|
|
142
|
+
const existing = await this.linkModel.findOne({
|
|
143
|
+
provider: identity.provider,
|
|
144
|
+
subject: identity.subject,
|
|
145
|
+
});
|
|
146
|
+
if (existing) {
|
|
147
|
+
if (existing.userId !== String(userId)) {
|
|
148
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_ALREADY_LINKED, 'This provider account is linked to another user.');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
await this.createLink(userId, identity);
|
|
153
|
+
}
|
|
154
|
+
return this.listLinks(userId);
|
|
155
|
+
}
|
|
156
|
+
async unlink(userId, linkId) {
|
|
157
|
+
const link = await this.linkModel.findOne({
|
|
158
|
+
_id: linkId,
|
|
159
|
+
userId: String(userId),
|
|
160
|
+
});
|
|
161
|
+
if (!link) {
|
|
162
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_LINK_NOTFOUND, 'Link not found.');
|
|
163
|
+
}
|
|
164
|
+
const user = await this.userModel.findById(userId);
|
|
165
|
+
const otherLinks = await this.linkModel.countDocuments({
|
|
166
|
+
userId: String(userId),
|
|
167
|
+
_id: { $ne: link._id },
|
|
168
|
+
});
|
|
169
|
+
if (!user?.passwordEncyripted && otherLinks === 0) {
|
|
170
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_LAST_LOGIN_METHOD, 'Set a password before removing your only sign-in method.');
|
|
171
|
+
}
|
|
172
|
+
await link.deleteOne();
|
|
173
|
+
return this.listLinks(userId);
|
|
174
|
+
}
|
|
175
|
+
async verify(providerName, credential) {
|
|
176
|
+
const provider = this.providers.find(providerName);
|
|
177
|
+
if (!provider) {
|
|
178
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_PROVIDER_NOTFOUND, 'OAuth provider is not available.');
|
|
179
|
+
}
|
|
180
|
+
if (!credential) {
|
|
181
|
+
throw this.invalidCredential();
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
return await provider.verify({ credential });
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.warn(`OAuth ${providerName} verification failed`, error);
|
|
188
|
+
throw this.invalidCredential();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async findSession(key) {
|
|
192
|
+
const session = await this.sessionModel.findOne({
|
|
193
|
+
_id: key,
|
|
194
|
+
expireAfter: { $gt: new Date() },
|
|
195
|
+
});
|
|
196
|
+
if (!session) {
|
|
197
|
+
throw this.sessionNotFound();
|
|
198
|
+
}
|
|
199
|
+
return session;
|
|
200
|
+
}
|
|
201
|
+
async createLink(userId, identity) {
|
|
202
|
+
await this.linkModel.create({
|
|
203
|
+
userId: String(userId),
|
|
204
|
+
provider: identity.provider,
|
|
205
|
+
subject: identity.subject,
|
|
206
|
+
email: identity.email,
|
|
207
|
+
linkedAt: new Date(),
|
|
208
|
+
lastLoginAt: new Date(),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
assertCanLogin(user) {
|
|
212
|
+
if (!user.active || user.suspended) {
|
|
213
|
+
throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.USER_INACTIVE, 'User is not active or is suspended.');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
loggedIn(provider, userId) {
|
|
217
|
+
return {
|
|
218
|
+
status: 'LOGGED_IN',
|
|
219
|
+
provider,
|
|
220
|
+
token: this.authService.issueToken(userId).token,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
async pending(session) {
|
|
224
|
+
const prefill = {
|
|
225
|
+
email: session.email,
|
|
226
|
+
name: session.name,
|
|
227
|
+
surname: session.surname,
|
|
228
|
+
picture: session.picture,
|
|
229
|
+
};
|
|
230
|
+
if (!session.existingUserId) {
|
|
231
|
+
prefill.usernameSuggestion = await this.suggestUsername(session.email);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
status: session.existingUserId
|
|
235
|
+
? 'LINK_REQUIRED'
|
|
236
|
+
: 'REGISTER_REQUIRED',
|
|
237
|
+
provider: session.provider,
|
|
238
|
+
sessionKey: session._id,
|
|
239
|
+
prefill,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async suggestUsername(email) {
|
|
243
|
+
const cleaned = email
|
|
244
|
+
.split('@')[0]
|
|
245
|
+
.toLowerCase()
|
|
246
|
+
.replace(/[^a-z0-9._]/g, '')
|
|
247
|
+
.replace(/^[^a-z]+/, '');
|
|
248
|
+
const base = (cleaned || 'user').slice(0, 11);
|
|
249
|
+
let candidate = base;
|
|
250
|
+
for (let i = 0; i < 10; i++) {
|
|
251
|
+
if (!(await this.userModel.exists({ username: candidate }))) {
|
|
252
|
+
return candidate;
|
|
253
|
+
}
|
|
254
|
+
candidate = `${base}${Math.floor(1000 + Math.random() * 9000)}`;
|
|
255
|
+
}
|
|
256
|
+
return candidate;
|
|
257
|
+
}
|
|
258
|
+
sessionNotFound() {
|
|
259
|
+
return new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_SESSION_NOTFOUND, 'Sign-in session expired; sign in with the provider again.');
|
|
260
|
+
}
|
|
261
|
+
invalidCredential() {
|
|
262
|
+
return new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.OAUTH_INVALID_CREDENTIAL, 'The provider credential could not be verified.');
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
exports.OAuthService = OAuthService;
|
|
266
|
+
exports.OAuthService = OAuthService = __decorate([
|
|
267
|
+
(0, common_1.Injectable)(),
|
|
268
|
+
__param(0, (0, mongoose_1.InjectModel)(users_entity_mongo_1.User.name)),
|
|
269
|
+
__param(1, (0, mongoose_1.InjectModel)(users_entity_mongo_1.UserOAuthLink.name)),
|
|
270
|
+
__param(2, (0, mongoose_1.InjectModel)(users_entity_mongo_1.OAuthLoginSession.name)),
|
|
271
|
+
__metadata("design:paramtypes", [mongoose_2.Model,
|
|
272
|
+
mongoose_2.Model,
|
|
273
|
+
mongoose_2.Model,
|
|
274
|
+
oauth_provider_registry_1.OAuthProviderRegistry,
|
|
275
|
+
user_service_1.UserService,
|
|
276
|
+
auth_service_1.AuthService])
|
|
277
|
+
], OAuthService);
|
|
278
|
+
//# sourceMappingURL=oauth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.service.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/services/oauth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAC/C,uCAAiC;AACjC,6DAOoC;AACpC,yEAI0C;AAC1C,8EAAyE;AAEzE,iDAA6C;AAC7C,iDAA6C;AAC7C,iDAA6C;AAE7C,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACtC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAarB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACrB,YACoC,SAAsB,EAE9C,SAA+B,EAE/B,YAAsC,EACtC,SAAgC,EAChC,WAAwB,EACxB,WAAwB;QAPA,cAAS,GAAT,SAAS,CAAa;QAE9C,cAAS,GAAT,SAAS,CAAsB;QAE/B,iBAAY,GAAZ,YAAY,CAA0B;QACtC,cAAS,GAAT,SAAS,CAAuB;QAChC,gBAAW,G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YAAY;IADxB,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,sBAAW,EAAC,yBAAI,CAAC,IAAI,CAAC,CAAA;IACtB,WAAA,IAAA,sBAAW,EAAC,kCAAa,CAAC,IAAI,CAAC,CAAA;IAE/B,WAAA,IAAA,sBAAW,EAAC,sCAAiB,CAAC,IAAI,CAAC,CAAA;qCAHO,gBAAK;QAE7B,gBAAK;QAEF,gBAAK;QACR,+CAAqB;QACnB,0BAAW;QACX,0BAAW;GAT3B,YAAY,CA8UxB"}
|
|
@@ -36,6 +36,9 @@ const jwt_local_strategy_1 = require("./strategies/jwt-local-strategy");
|
|
|
36
36
|
const entity_ownership_mapper_1 = require("./mapper/entity-ownership.mapper");
|
|
37
37
|
const entity_ownership_group_mapper_1 = require("./mapper/entity-ownership-group.mapper");
|
|
38
38
|
const eog_assertions_1 = require("./util/eog-assertions");
|
|
39
|
+
const oauth_controller_1 = require("./web/oauth.controller");
|
|
40
|
+
const oauth_service_1 = require("./services/oauth.service");
|
|
41
|
+
const oauth_provider_registry_1 = require("./oauth/oauth-provider-registry");
|
|
39
42
|
let UsersWebserviceModule = class UsersWebserviceModule {
|
|
40
43
|
};
|
|
41
44
|
exports.UsersWebserviceModule = UsersWebserviceModule;
|
|
@@ -50,6 +53,7 @@ exports.UsersWebserviceModule = UsersWebserviceModule = __decorate([
|
|
|
50
53
|
controllers: [
|
|
51
54
|
user_controller_1.UserController,
|
|
52
55
|
auth_controller_1.AuthController,
|
|
56
|
+
oauth_controller_1.OAuthController,
|
|
53
57
|
user_admin_controller_1.UserAdminController,
|
|
54
58
|
password_reset_controller_1.ResetPasswordController,
|
|
55
59
|
entity_ownership_controller_1.EntityOwnershipController,
|
|
@@ -73,7 +77,9 @@ exports.UsersWebserviceModule = UsersWebserviceModule = __decorate([
|
|
|
73
77
|
entity_ownership_mapper_1.EntityOwnershipMapper,
|
|
74
78
|
entity_ownership_group_service_1.EntityOwnershipGroupService,
|
|
75
79
|
entity_ownership_group_mapper_1.EntityOwnershipGroupMapper,
|
|
76
|
-
eog_assertions_1.EogAssertions
|
|
80
|
+
eog_assertions_1.EogAssertions,
|
|
81
|
+
oauth_service_1.OAuthService,
|
|
82
|
+
oauth_provider_registry_1.OAuthProviderRegistry,
|
|
77
83
|
],
|
|
78
84
|
exports: [user_service_1.UserService, user_common_service_1.UserCommonService, auth_service_1.AuthService, entity_ownership_service_1.EntityOwnershipService, entity_ownership_group_service_1.EntityOwnershipGroupService],
|
|
79
85
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users-webservice.module.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/users-webservice.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AAExC,+DAAiE;AACjE,uFAAsF;AACtF,mFAA8H;AAC9H,yEAA0E;AAC1E,2DAAuD;AACvD,2DAAuD;AACvD,uEAAkE;AAClE,+EAA0E;AAC1E,mFAA8E;AAC9E,qFAAgF;AAChF,qFAA4E;AAC5E,yHAAkH;AAClH,+FAAyF;AACzF,6GAAsG;AACtG,0DAAsD;AACtD,wEAAmE;AACnE,4EAAuE;AACvE,0DAAsD;AACtD,0FAAoF;AACpF,8EAAyE;AACzE,4DAAwD;AACxD,kFAA6E;AAC7E,8FAAwF;AACxF,6DAA4D;AAC5D,wEAAmE;AACnE,8EAAyE;AACzE,0FAAoF;AACpF,0DAAsD;
|
|
1
|
+
{"version":3,"file":"users-webservice.module.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/users-webservice.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AAExC,+DAAiE;AACjE,uFAAsF;AACtF,mFAA8H;AAC9H,yEAA0E;AAC1E,2DAAuD;AACvD,2DAAuD;AACvD,uEAAkE;AAClE,+EAA0E;AAC1E,mFAA8E;AAC9E,qFAAgF;AAChF,qFAA4E;AAC5E,yHAAkH;AAClH,+FAAyF;AACzF,6GAAsG;AACtG,0DAAsD;AACtD,wEAAmE;AACnE,4EAAuE;AACvE,0DAAsD;AACtD,0FAAoF;AACpF,8EAAyE;AACzE,4DAAwD;AACxD,kFAA6E;AAC7E,8FAAwF;AACxF,6DAA4D;AAC5D,wEAAmE;AACnE,8EAAyE;AACzE,0FAAoF;AACpF,0DAAsD;AACtD,6DAAyD;AACzD,4DAAwD;AACxD,6EAAwE;AA2CjE,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;CAAG,CAAA;AAAxB,sDAAqB;gCAArB,qBAAqB;IAzCjC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,2CAAsB;YACtB,kCAAkB;YAClB,GAAG,uDAA2B;YAC9B,mDAAyB;SAE1B;QACD,WAAW,EAAE;YACX,gCAAc;YACd,gCAAc;YACd,kCAAe;YACf,2CAAmB;YACnB,mDAAuB;YACvB,uDAAyB;YACzB,yDAA0B;YAC1B,qDAAsB;YACtB,2FAA0C;YAC1C,kEAA8B;YAC9B,+EAAoC;SACrC;QACD,SAAS,EAAE;YACT,0BAAW;YACX,uCAAiB;YACjB,2CAAmB;YACnB,0BAAW;YACX,wDAAyB;YACzB,mCAAiB;YACjB,qCAAgB;YAChB,6CAAoB;YACpB,4BAAY;YACZ,iDAAsB;YACtB,+CAAqB;YACrB,4DAA2B;YAC3B,0DAA0B;YAC1B,8BAAa;YACb,4BAAY;YACZ,+CAAqB;SACtB;QACD,OAAO,EAAE,CAAC,0BAAW,EAAE,uCAAiB,EAAE,0BAAW,EAAE,iDAAsB,EAAE,4DAA2B,CAAC;KAC5G,CAAC;GACW,qBAAqB,CAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OAuthCompleteRegistrationDTO, OAuthCredentialDTO, OAuthLinkWithPasswordDTO, UserAuthBackendDTO } from '@ubs-platform/users-common';
|
|
2
|
+
import { OAuthService } from '../services/oauth.service';
|
|
3
|
+
export declare class OAuthController {
|
|
4
|
+
private oauthService;
|
|
5
|
+
constructor(oauthService: OAuthService);
|
|
6
|
+
providers(): import("@ubs-platform/users-common").OAuthProviderInfoDTO[];
|
|
7
|
+
login(provider: string, body: OAuthCredentialDTO): Promise<import("@ubs-platform/users-common").OAuthLoginResultDTO>;
|
|
8
|
+
session(key: string): Promise<import("@ubs-platform/users-common").OAuthLoginResultDTO>;
|
|
9
|
+
register(key: string, body: OAuthCompleteRegistrationDTO): Promise<import("@ubs-platform/users-common").OAuthLoginResultDTO>;
|
|
10
|
+
linkWithPassword(key: string, body: OAuthLinkWithPasswordDTO): Promise<import("@ubs-platform/users-common").OAuthLoginResultDTO>;
|
|
11
|
+
links(user: UserAuthBackendDTO): Promise<import("@ubs-platform/users-common").OAuthLinkDTO[]>;
|
|
12
|
+
addLink(user: UserAuthBackendDTO, provider: string, body: OAuthCredentialDTO): Promise<import("@ubs-platform/users-common").OAuthLinkDTO[]>;
|
|
13
|
+
removeLink(user: UserAuthBackendDTO, id: string): Promise<import("@ubs-platform/users-common").OAuthLinkDTO[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OAuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const users_common_1 = require("@ubs-platform/users-common");
|
|
18
|
+
const jwt_local_guard_1 = require("../guard/jwt-local.guard");
|
|
19
|
+
const local_current_user_decorator_1 = require("../local-current-user-decorator");
|
|
20
|
+
const oauth_service_1 = require("../services/oauth.service");
|
|
21
|
+
let OAuthController = class OAuthController {
|
|
22
|
+
constructor(oauthService) {
|
|
23
|
+
this.oauthService = oauthService;
|
|
24
|
+
}
|
|
25
|
+
providers() {
|
|
26
|
+
return this.oauthService.listProviders();
|
|
27
|
+
}
|
|
28
|
+
login(provider, body) {
|
|
29
|
+
return handle(() => this.oauthService.login(provider, body?.credential));
|
|
30
|
+
}
|
|
31
|
+
session(key) {
|
|
32
|
+
return handle(() => this.oauthService.getSession(key));
|
|
33
|
+
}
|
|
34
|
+
register(key, body) {
|
|
35
|
+
return handle(() => this.oauthService.completeRegistration(key, body));
|
|
36
|
+
}
|
|
37
|
+
linkWithPassword(key, body) {
|
|
38
|
+
return handle(() => this.oauthService.linkWithPassword(key, body?.password));
|
|
39
|
+
}
|
|
40
|
+
links(user) {
|
|
41
|
+
return this.oauthService.listLinks(user.id);
|
|
42
|
+
}
|
|
43
|
+
addLink(user, provider, body) {
|
|
44
|
+
return handle(() => this.oauthService.linkToUser(user.id, provider, body?.credential));
|
|
45
|
+
}
|
|
46
|
+
removeLink(user, id) {
|
|
47
|
+
return handle(() => this.oauthService.unlink(user.id, id));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.OAuthController = OAuthController;
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, common_1.Get)('providers'),
|
|
53
|
+
__metadata("design:type", Function),
|
|
54
|
+
__metadata("design:paramtypes", []),
|
|
55
|
+
__metadata("design:returntype", void 0)
|
|
56
|
+
], OAuthController.prototype, "providers", null);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, common_1.Post)('login/:provider'),
|
|
59
|
+
__param(0, (0, common_1.Param)('provider')),
|
|
60
|
+
__param(1, (0, common_1.Body)()),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", [String, users_common_1.OAuthCredentialDTO]),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], OAuthController.prototype, "login", null);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, common_1.Get)('session/:key'),
|
|
67
|
+
__param(0, (0, common_1.Param)('key')),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [String]),
|
|
70
|
+
__metadata("design:returntype", void 0)
|
|
71
|
+
], OAuthController.prototype, "session", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, common_1.Post)('session/:key/register'),
|
|
74
|
+
__param(0, (0, common_1.Param)('key')),
|
|
75
|
+
__param(1, (0, common_1.Body)()),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [String, users_common_1.OAuthCompleteRegistrationDTO]),
|
|
78
|
+
__metadata("design:returntype", void 0)
|
|
79
|
+
], OAuthController.prototype, "register", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, common_1.Post)('session/:key/link'),
|
|
82
|
+
__param(0, (0, common_1.Param)('key')),
|
|
83
|
+
__param(1, (0, common_1.Body)()),
|
|
84
|
+
__metadata("design:type", Function),
|
|
85
|
+
__metadata("design:paramtypes", [String, users_common_1.OAuthLinkWithPasswordDTO]),
|
|
86
|
+
__metadata("design:returntype", void 0)
|
|
87
|
+
], OAuthController.prototype, "linkWithPassword", null);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, common_1.Get)('links'),
|
|
90
|
+
(0, common_1.UseGuards)(jwt_local_guard_1.JwtAuthLocalGuard),
|
|
91
|
+
__param(0, (0, local_current_user_decorator_1.CurrentUser)()),
|
|
92
|
+
__metadata("design:type", Function),
|
|
93
|
+
__metadata("design:paramtypes", [users_common_1.UserAuthBackendDTO]),
|
|
94
|
+
__metadata("design:returntype", void 0)
|
|
95
|
+
], OAuthController.prototype, "links", null);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, common_1.Post)('links/:provider'),
|
|
98
|
+
(0, common_1.UseGuards)(jwt_local_guard_1.JwtAuthLocalGuard),
|
|
99
|
+
__param(0, (0, local_current_user_decorator_1.CurrentUser)()),
|
|
100
|
+
__param(1, (0, common_1.Param)('provider')),
|
|
101
|
+
__param(2, (0, common_1.Body)()),
|
|
102
|
+
__metadata("design:type", Function),
|
|
103
|
+
__metadata("design:paramtypes", [users_common_1.UserAuthBackendDTO, String, users_common_1.OAuthCredentialDTO]),
|
|
104
|
+
__metadata("design:returntype", void 0)
|
|
105
|
+
], OAuthController.prototype, "addLink", null);
|
|
106
|
+
__decorate([
|
|
107
|
+
(0, common_1.Delete)('links/:id'),
|
|
108
|
+
(0, common_1.UseGuards)(jwt_local_guard_1.JwtAuthLocalGuard),
|
|
109
|
+
__param(0, (0, local_current_user_decorator_1.CurrentUser)()),
|
|
110
|
+
__param(1, (0, common_1.Param)('id')),
|
|
111
|
+
__metadata("design:type", Function),
|
|
112
|
+
__metadata("design:paramtypes", [users_common_1.UserAuthBackendDTO, String]),
|
|
113
|
+
__metadata("design:returntype", void 0)
|
|
114
|
+
], OAuthController.prototype, "removeLink", null);
|
|
115
|
+
exports.OAuthController = OAuthController = __decorate([
|
|
116
|
+
(0, common_1.Controller)('auth/oauth'),
|
|
117
|
+
__metadata("design:paramtypes", [oauth_service_1.OAuthService])
|
|
118
|
+
], OAuthController);
|
|
119
|
+
const UNAUTHORIZED_KEYS = new Set([
|
|
120
|
+
users_common_1.UBSUsersErrorConsts.OAUTH_INVALID_CREDENTIAL,
|
|
121
|
+
users_common_1.UBSUsersErrorConsts.AUTHENTICATION_FAIL,
|
|
122
|
+
]);
|
|
123
|
+
async function handle(action) {
|
|
124
|
+
try {
|
|
125
|
+
return await action();
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error instanceof users_common_1.ErrorInformations) {
|
|
129
|
+
const status = UNAUTHORIZED_KEYS.has(error.key)
|
|
130
|
+
? common_1.HttpStatus.UNAUTHORIZED
|
|
131
|
+
: error.key === users_common_1.UBSUsersErrorConsts.OAUTH_TOO_MANY_ATTEMPTS
|
|
132
|
+
? common_1.HttpStatus.TOO_MANY_REQUESTS
|
|
133
|
+
: common_1.HttpStatus.BAD_REQUEST;
|
|
134
|
+
throw new common_1.HttpException(error, status);
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=oauth.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../../../../../../libs/users-webservice/src/web/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,6DAOoC;AACpC,8DAA6D;AAC7D,kFAA8D;AAC9D,6DAAyD;AAGlD,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAGlD,SAAS;QACL,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;IAC7C,CAAC;IAGD,KAAK,CAAoB,QAAgB,EAAU,IAAwB;QACvE,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7E,CAAC;IAGD,OAAO,CAAe,GAAW;QAC7B,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IAGD,QAAQ,CACU,GAAW,EACjB,IAAkC;QAE1C,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,IAA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