@my-nestjs-kit/auth 0.0.0-stage → 0.1.0-dev.20261129010337
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/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/access-tokens/access-token.d.ts +13 -0
- package/dist/access-tokens/access-token.js +10 -0
- package/dist/access-tokens/access-tokens.module.d.ts +2 -0
- package/dist/access-tokens/access-tokens.module.js +22 -0
- package/dist/access-tokens/access-tokens.service.d.ts +16 -0
- package/dist/access-tokens/access-tokens.service.js +72 -0
- package/dist/access-tokens/access-tokens.types.d.ts +5 -0
- package/dist/access-tokens/access-tokens.types.js +9 -0
- package/dist/access-tokens/dto/access-token.dto.d.ts +13 -0
- package/dist/access-tokens/dto/access-token.dto.js +33 -0
- package/dist/auth-sessions/devices/dto/create-device.dto.d.ts +6 -0
- package/dist/auth-sessions/devices/dto/create-device.dto.js +33 -0
- package/dist/auth-sessions/dto/create-auth-session.dto.d.ts +8 -0
- package/dist/auth-sessions/dto/create-auth-session.dto.js +36 -0
- package/dist/auth.constants.d.ts +30 -0
- package/dist/auth.constants.js +36 -0
- package/dist/decorators/GetAuthParams.decorator.d.ts +34 -0
- package/dist/decorators/GetAuthParams.decorator.js +64 -0
- package/dist/decorators/GetSession.decorator.d.ts +2 -0
- package/dist/decorators/GetSession.decorator.js +13 -0
- package/dist/decorators/GetUser.decorator.d.ts +2 -0
- package/dist/decorators/GetUser.decorator.js +13 -0
- package/dist/decorators/Public.decorator.d.ts +3 -0
- package/dist/decorators/Public.decorator.js +18 -0
- package/dist/decorators/SetAuthConfig.decorator.d.ts +3 -0
- package/dist/decorators/SetAuthConfig.decorator.js +13 -0
- package/dist/dto/confirm-secure-action.dto.d.ts +8 -0
- package/dist/dto/confirm-secure-action.dto.js +46 -0
- package/dist/dto/log-in-by-email.dto.d.ts +16 -0
- package/dist/dto/log-in-by-email.dto.js +15 -0
- package/dist/dto/login-user-auth.dto.d.ts +4 -0
- package/dist/dto/login-user-auth.dto.js +29 -0
- package/dist/dto/verify-user-registration.dto.d.ts +4 -0
- package/dist/dto/verify-user-registration.dto.js +25 -0
- package/dist/entities/abstract-device-base.entity.d.ts +10 -0
- package/dist/entities/abstract-device-base.entity.js +77 -0
- package/dist/entities/abstract-o-auth-connection.entity.d.ts +28 -0
- package/dist/entities/abstract-o-auth-connection.entity.js +100 -0
- package/dist/entities/abstract-o-auth-profile.entity.d.ts +10 -0
- package/dist/entities/abstract-o-auth-profile.entity.js +38 -0
- package/dist/entities/auth-session-base.entity.d.ts +18 -0
- package/dist/entities/auth-session-base.entity.js +73 -0
- package/dist/guards/AbstractRefreshJwtToken.guard.d.ts +9 -0
- package/dist/guards/AbstractRefreshJwtToken.guard.js +45 -0
- package/dist/guards/abstract/AppAuthGuard-abstract.d.ts +219 -0
- package/dist/guards/abstract/AppAuthGuard-abstract.js +187 -0
- package/dist/guards/index.d.ts +0 -0
- package/dist/guards/index.js +0 -0
- package/dist/helper/base-auth-service.helper.d.ts +60 -0
- package/dist/helper/base-auth-service.helper.js +184 -0
- package/dist/helper/jsw-auth-controller-abstract.d.ts +33 -0
- package/dist/helper/jsw-auth-controller-abstract.js +89 -0
- package/dist/helper/jwt-auth-service-abstract.d.ts +40 -0
- package/dist/helper/jwt-auth-service-abstract.js +181 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +55 -0
- package/dist/jwt/index.d.ts +5 -0
- package/dist/jwt/index.js +21 -0
- package/dist/jwt/jwt-auth.module.d.ts +6 -0
- package/dist/jwt/jwt-auth.module.js +45 -0
- package/dist/jwt/jwt-auth.service.d.ts +33 -0
- package/dist/jwt/jwt-auth.service.js +170 -0
- package/dist/jwt/jwt-keys.helper.d.ts +12 -0
- package/dist/jwt/jwt-keys.helper.js +32 -0
- package/dist/jwt/types/enums.d.ts +19 -0
- package/dist/jwt/types/enums.js +26 -0
- package/dist/jwt/types/index.d.ts +2 -0
- package/dist/jwt/types/index.js +18 -0
- package/dist/jwt/types/jwt-auth.types.d.ts +44 -0
- package/dist/jwt/types/jwt-auth.types.js +2 -0
- package/dist/o-auth/abstract-o-auth.service.d.ts +30 -0
- package/dist/o-auth/abstract-o-auth.service.js +64 -0
- package/dist/o-auth/o-auth.namespace.d.ts +131 -0
- package/dist/o-auth/o-auth.namespace.js +256 -0
- package/dist/o-auth/sdk/base-ext-o-auth-sdk.d.ts +104 -0
- package/dist/o-auth/sdk/base-ext-o-auth-sdk.js +56 -0
- package/dist/route-auth-configs.helper.d.ts +29 -0
- package/dist/route-auth-configs.helper.js +36 -0
- package/dist/services/abstrac-auth-sessions.service.d.ts +28 -0
- package/dist/services/abstrac-auth-sessions.service.js +41 -0
- package/dist/services/abstract-sessions-repo.service.d.ts +28 -0
- package/dist/services/abstract-sessions-repo.service.js +28 -0
- package/dist/types/app-request.inteface.d.ts +14 -0
- package/dist/types/app-request.inteface.js +2 -0
- package/dist/types/auth.types.d.ts +43 -0
- package/dist/types/auth.types.js +12 -0
- package/dist/types/ws-client.types.d.ts +14 -0
- package/dist/types/ws-client.types.js +2 -0
- package/package.json +95 -3
|
@@ -0,0 +1,256 @@
|
|
|
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.OAuth = void 0;
|
|
13
|
+
const core_1 = require("@my-nestjs-kit/core");
|
|
14
|
+
const core_2 = require("@my-nestjs-kit/core");
|
|
15
|
+
const class_validator_1 = require("class-validator");
|
|
16
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
17
|
+
const route_auth_configs_helper_1 = require("../route-auth-configs.helper");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const SetAuthConfig_decorator_1 = require("../decorators/SetAuthConfig.decorator");
|
|
20
|
+
const create_auth_session_dto_1 = require("../auth-sessions/dto/create-auth-session.dto");
|
|
21
|
+
const core_3 = require("@my-nestjs-kit/core");
|
|
22
|
+
var OAuth;
|
|
23
|
+
(function (OAuth) {
|
|
24
|
+
// export enum RewritesNamespace {
|
|
25
|
+
// callback = AUTH_O_PATH + '/callback',
|
|
26
|
+
// logIn = AUTH_O_PATH + '/logIn',
|
|
27
|
+
// authUrl = AUTH_O_PATH + '/auth-url',
|
|
28
|
+
// saveTokens = AUTH_O_PATH + '/save-tokens',
|
|
29
|
+
// }
|
|
30
|
+
let Provider;
|
|
31
|
+
(function (Provider) {
|
|
32
|
+
Provider.configsMap = {
|
|
33
|
+
[core_3.ProviderNameEnum.facebook]: {
|
|
34
|
+
scopes: ['email', 'openID', 'profile'],
|
|
35
|
+
idKey: 'sub',
|
|
36
|
+
},
|
|
37
|
+
[core_3.ProviderNameEnum.google]: {
|
|
38
|
+
scopes: ['email', 'openID', 'profile'],
|
|
39
|
+
idKey: 'sub',
|
|
40
|
+
},
|
|
41
|
+
[core_3.ProviderNameEnum.refme]: {
|
|
42
|
+
scopes: ['email', 'openID', 'reference', 'profile', 'wallets'],
|
|
43
|
+
idKey: 'userId',
|
|
44
|
+
},
|
|
45
|
+
[core_3.ProviderNameEnum.mia]: {
|
|
46
|
+
scopes: ['email', 'openID', 'reference', 'profile'],
|
|
47
|
+
idKey: 'userId',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
class ExtraDataJson {
|
|
51
|
+
}
|
|
52
|
+
let ExtraDataJsonByType;
|
|
53
|
+
(function (ExtraDataJsonByType) {
|
|
54
|
+
var _a, _b, _c, _d, _e;
|
|
55
|
+
class Google {
|
|
56
|
+
constructor() {
|
|
57
|
+
this.engagementSource = null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, core_2.IsString128)(),
|
|
62
|
+
__metadata("design:type", String)
|
|
63
|
+
], Google.prototype, "engagementSource", void 0);
|
|
64
|
+
ExtraDataJsonByType.Google = Google;
|
|
65
|
+
class Refme {
|
|
66
|
+
constructor() {
|
|
67
|
+
this.reference = null;
|
|
68
|
+
this.engagementSource = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, core_2.IsString128)(),
|
|
73
|
+
__metadata("design:type", String)
|
|
74
|
+
], Refme.prototype, "reference", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, core_2.IsString128)(),
|
|
77
|
+
__metadata("design:type", String)
|
|
78
|
+
], Refme.prototype, "engagementSource", void 0);
|
|
79
|
+
ExtraDataJsonByType.Refme = Refme;
|
|
80
|
+
class Mia {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.reference = null;
|
|
83
|
+
this.engagementSource = null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, core_2.IsString128)(),
|
|
88
|
+
__metadata("design:type", String)
|
|
89
|
+
], Mia.prototype, "reference", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, core_2.IsString128)(),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], Mia.prototype, "engagementSource", void 0);
|
|
94
|
+
ExtraDataJsonByType.Mia = Mia;
|
|
95
|
+
class MappedData extends ExtraDataJson {
|
|
96
|
+
constructor() {
|
|
97
|
+
super(...arguments);
|
|
98
|
+
this[_a] = new Google();
|
|
99
|
+
this[_b] = new ExtraDataJson();
|
|
100
|
+
this[_c] = new ExtraDataJson();
|
|
101
|
+
this[_d] = new Refme();
|
|
102
|
+
this[_e] = new Mia();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
_a = core_3.ProviderNameEnum.google, _b = core_3.ProviderNameEnum.facebook, _c = core_3.ProviderNameEnum.meta, _d = core_3.ProviderNameEnum.refme, _e = core_3.ProviderNameEnum.mia;
|
|
106
|
+
ExtraDataJsonByType.MappedData = MappedData;
|
|
107
|
+
})(ExtraDataJsonByType = Provider.ExtraDataJsonByType || (Provider.ExtraDataJsonByType = {}));
|
|
108
|
+
})(Provider = OAuth.Provider || (OAuth.Provider = {}));
|
|
109
|
+
let ActionType;
|
|
110
|
+
(function (ActionType) {
|
|
111
|
+
ActionType["callback"] = "callback";
|
|
112
|
+
ActionType["auth_url"] = "auth-url";
|
|
113
|
+
ActionType["save_tokens"] = "save-tokens";
|
|
114
|
+
ActionType["logIn"] = "logIn";
|
|
115
|
+
})(ActionType = OAuth.ActionType || (OAuth.ActionType = {}));
|
|
116
|
+
let TokenType;
|
|
117
|
+
(function (TokenType) {
|
|
118
|
+
TokenType["Bearer"] = "Bearer";
|
|
119
|
+
})(TokenType = OAuth.TokenType || (OAuth.TokenType = {}));
|
|
120
|
+
class MetaStorage extends route_auth_configs_helper_1.AuthConfigsMetaStorage {
|
|
121
|
+
constructor(payload) {
|
|
122
|
+
payload.model = { refme: true };
|
|
123
|
+
super(payload);
|
|
124
|
+
// Object.assign(this, payload);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
MetaStorage.KEY = 'o_auth_config';
|
|
128
|
+
OAuth.MetaStorage = MetaStorage;
|
|
129
|
+
function RouteMeta(meta) {
|
|
130
|
+
return (0, common_1.applyDecorators)((0, SetAuthConfig_decorator_1.SetAuthConfig)({
|
|
131
|
+
model: { refme: true },
|
|
132
|
+
isPublic: meta.isPublic ?? true,
|
|
133
|
+
}), (0, common_1.SetMetadata)(MetaStorage.KEY, new MetaStorage(meta)));
|
|
134
|
+
}
|
|
135
|
+
OAuth.RouteMeta = RouteMeta;
|
|
136
|
+
let Server;
|
|
137
|
+
(function (Server) {
|
|
138
|
+
class BaseIncomingQuery {
|
|
139
|
+
constructor(payload) {
|
|
140
|
+
if (payload)
|
|
141
|
+
Object.assign(this, payload);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, core_2.IsString128)(),
|
|
146
|
+
__metadata("design:type", String)
|
|
147
|
+
], BaseIncomingQuery.prototype, "publicKey", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
(0, core_2.IsString128)({ optional: true }),
|
|
150
|
+
__metadata("design:type", String)
|
|
151
|
+
], BaseIncomingQuery.prototype, "privateKey", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
(0, core_2.IsString16)(),
|
|
154
|
+
__metadata("design:type", String)
|
|
155
|
+
], BaseIncomingQuery.prototype, "code", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, core_2.IsURLProperty)(),
|
|
158
|
+
__metadata("design:type", String)
|
|
159
|
+
], BaseIncomingQuery.prototype, "redirectUri", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, core_2.IsString16)({ each: true }),
|
|
162
|
+
__metadata("design:type", Array)
|
|
163
|
+
], BaseIncomingQuery.prototype, "scopes", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
(0, core_2.IsEnumProperty)(core_3.ProviderNameEnum),
|
|
166
|
+
__metadata("design:type", Object)
|
|
167
|
+
], BaseIncomingQuery.prototype, "provider", void 0);
|
|
168
|
+
Server.BaseIncomingQuery = BaseIncomingQuery;
|
|
169
|
+
class GetAuthUrlQuery extends BaseIncomingQuery {
|
|
170
|
+
}
|
|
171
|
+
Server.GetAuthUrlQuery = GetAuthUrlQuery;
|
|
172
|
+
class SaveExtTokensDto extends (0, swagger_1.IntersectionType)(BaseIncomingQuery, create_auth_session_dto_1.CreateAuthSessionDto) {
|
|
173
|
+
}
|
|
174
|
+
__decorate([
|
|
175
|
+
(0, class_validator_1.IsJWT)(),
|
|
176
|
+
(0, core_1.ApiPropDescriptor)({ optional: false }),
|
|
177
|
+
__metadata("design:type", String)
|
|
178
|
+
], SaveExtTokensDto.prototype, "access_token", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
(0, class_validator_1.IsJWT)(),
|
|
181
|
+
(0, core_1.ApiPropDescriptor)({ optional: false }),
|
|
182
|
+
__metadata("design:type", String)
|
|
183
|
+
], SaveExtTokensDto.prototype, "refresh_token", void 0);
|
|
184
|
+
__decorate([
|
|
185
|
+
(0, class_validator_1.IsEmail)(),
|
|
186
|
+
(0, class_validator_1.IsOptional)(),
|
|
187
|
+
(0, core_1.ApiPropDescriptor)({ optional: false }),
|
|
188
|
+
(0, class_validator_1.ValidateIf)((ref) => !ref.userId),
|
|
189
|
+
__metadata("design:type", String)
|
|
190
|
+
], SaveExtTokensDto.prototype, "email", void 0);
|
|
191
|
+
__decorate([
|
|
192
|
+
(0, class_validator_1.IsUUID)(),
|
|
193
|
+
(0, class_validator_1.IsOptional)(),
|
|
194
|
+
(0, core_1.ApiPropDescriptor)(),
|
|
195
|
+
(0, class_validator_1.ValidateIf)((ref) => !ref.email),
|
|
196
|
+
__metadata("design:type", String)
|
|
197
|
+
], SaveExtTokensDto.prototype, "userId", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
(0, core_2.IsString128)({ optional: false }),
|
|
200
|
+
__metadata("design:type", String)
|
|
201
|
+
], SaveExtTokensDto.prototype, "extId", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
(0, core_2.IsString128)(),
|
|
204
|
+
__metadata("design:type", String)
|
|
205
|
+
], SaveExtTokensDto.prototype, "reference", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
(0, core_2.IsString128)({ optional: true }),
|
|
208
|
+
__metadata("design:type", String)
|
|
209
|
+
], SaveExtTokensDto.prototype, "tokenType", void 0);
|
|
210
|
+
__decorate([
|
|
211
|
+
(0, core_2.IsEnumProperty)(core_3.ProviderNameEnum),
|
|
212
|
+
__metadata("design:type", String)
|
|
213
|
+
], SaveExtTokensDto.prototype, "provider", void 0);
|
|
214
|
+
Server.SaveExtTokensDto = SaveExtTokensDto;
|
|
215
|
+
})(Server = OAuth.Server || (OAuth.Server = {}));
|
|
216
|
+
let Client;
|
|
217
|
+
(function (Client) {
|
|
218
|
+
class GetAuthUrlQuery extends Server.BaseIncomingQuery {
|
|
219
|
+
}
|
|
220
|
+
__decorate([
|
|
221
|
+
(0, core_2.IsEnumProperty)(core_3.ProviderNameEnum),
|
|
222
|
+
__metadata("design:type", String)
|
|
223
|
+
], GetAuthUrlQuery.prototype, "provider", void 0);
|
|
224
|
+
Client.GetAuthUrlQuery = GetAuthUrlQuery;
|
|
225
|
+
class CallbackQuery extends Server.BaseIncomingQuery {
|
|
226
|
+
}
|
|
227
|
+
__decorate([
|
|
228
|
+
(0, core_2.IsString128)({ optional: false }),
|
|
229
|
+
__metadata("design:type", String)
|
|
230
|
+
], CallbackQuery.prototype, "code", void 0);
|
|
231
|
+
__decorate([
|
|
232
|
+
(0, core_2.IsString128)(),
|
|
233
|
+
__metadata("design:type", String)
|
|
234
|
+
], CallbackQuery.prototype, "state", void 0);
|
|
235
|
+
__decorate([
|
|
236
|
+
(0, core_2.IsString128)(),
|
|
237
|
+
__metadata("design:type", String)
|
|
238
|
+
], CallbackQuery.prototype, "scope", void 0);
|
|
239
|
+
Client.CallbackQuery = CallbackQuery;
|
|
240
|
+
})(Client = OAuth.Client || (OAuth.Client = {}));
|
|
241
|
+
function getConfigsByProvider(provider) {
|
|
242
|
+
switch (provider) {
|
|
243
|
+
case 'refme': {
|
|
244
|
+
return {
|
|
245
|
+
getId: (entry) => entry['userId'],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
case 'google': {
|
|
249
|
+
return {
|
|
250
|
+
getId: (entry) => entry['sub'],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
OAuth.getConfigsByProvider = getConfigsByProvider;
|
|
256
|
+
})(OAuth || (exports.OAuth = OAuth = {}));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AppHttpExceptionResponse, HttpSuccessRes } from '@my-nestjs-kit/core';
|
|
2
|
+
import { AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
3
|
+
import { OAuth } from '../o-auth.namespace';
|
|
4
|
+
import { Logger } from '@nestjs/common';
|
|
5
|
+
import { ProviderNameEnum } from '@my-nestjs-kit/core';
|
|
6
|
+
export declare namespace OAuthSdk {
|
|
7
|
+
export enum GrantType {
|
|
8
|
+
AUTHORIZATION_CODE = "authorization_code",
|
|
9
|
+
REFRESH_TOKEN = "refresh_token"
|
|
10
|
+
}
|
|
11
|
+
export enum ResponseType {
|
|
12
|
+
CODE = "code"
|
|
13
|
+
}
|
|
14
|
+
export enum TokenStatus {
|
|
15
|
+
VALID = "valid",
|
|
16
|
+
INVALID = "invalid"
|
|
17
|
+
}
|
|
18
|
+
export type Connection = OAuth.Connection.Entity;
|
|
19
|
+
export type AuthorizationRequestParams = {
|
|
20
|
+
publicKey: string;
|
|
21
|
+
redirectUri: string;
|
|
22
|
+
scope: string;
|
|
23
|
+
state?: string;
|
|
24
|
+
grandType?: GrantType;
|
|
25
|
+
};
|
|
26
|
+
export type AuthorizationResponse = {
|
|
27
|
+
code: string;
|
|
28
|
+
state?: string;
|
|
29
|
+
};
|
|
30
|
+
export type AccessTokenRequest = {
|
|
31
|
+
publicKey: string;
|
|
32
|
+
privateKey: string;
|
|
33
|
+
redirectUri: string;
|
|
34
|
+
code?: string;
|
|
35
|
+
state?: string;
|
|
36
|
+
scope?: string;
|
|
37
|
+
responseType?: string;
|
|
38
|
+
};
|
|
39
|
+
export type RefreshTokenRequestParams = {
|
|
40
|
+
refresh_token?: string;
|
|
41
|
+
publicKey: string;
|
|
42
|
+
privateKey: string;
|
|
43
|
+
redirectUri: string;
|
|
44
|
+
scope?: string;
|
|
45
|
+
};
|
|
46
|
+
export type TokenResponse<Provider extends ProviderNameEnum = ProviderNameEnum> = {
|
|
47
|
+
access_token: string;
|
|
48
|
+
refresh_token?: string;
|
|
49
|
+
tokenType: string;
|
|
50
|
+
expiresIn: number;
|
|
51
|
+
scope?: string;
|
|
52
|
+
scopes?: string[];
|
|
53
|
+
extId: string;
|
|
54
|
+
email: string;
|
|
55
|
+
reference?: string;
|
|
56
|
+
provider?: Provider;
|
|
57
|
+
name?: {
|
|
58
|
+
first?: string;
|
|
59
|
+
second?: string;
|
|
60
|
+
};
|
|
61
|
+
imgUrl?: string;
|
|
62
|
+
};
|
|
63
|
+
export type TokenIntrospectionRequest = {
|
|
64
|
+
token: string;
|
|
65
|
+
token_type_hint?: string;
|
|
66
|
+
client_id: string;
|
|
67
|
+
client_secret: string;
|
|
68
|
+
};
|
|
69
|
+
export type TokenIntrospectionResponse = {
|
|
70
|
+
active: boolean;
|
|
71
|
+
scope: string[];
|
|
72
|
+
client_id: string;
|
|
73
|
+
user_id: string;
|
|
74
|
+
exp: number;
|
|
75
|
+
};
|
|
76
|
+
export type AsyncResponse<Data> = Promise<HttpSuccessRes<Data>>;
|
|
77
|
+
export type GetAuthURlResult = {
|
|
78
|
+
authUrl: string;
|
|
79
|
+
};
|
|
80
|
+
type Options = {
|
|
81
|
+
isDevMode?: boolean;
|
|
82
|
+
provider: ProviderNameEnum;
|
|
83
|
+
} & (HasClient | HasConfig);
|
|
84
|
+
type HasClient = {
|
|
85
|
+
client: AxiosInstance;
|
|
86
|
+
};
|
|
87
|
+
type HasConfig = {
|
|
88
|
+
config: CreateAxiosDefaults;
|
|
89
|
+
};
|
|
90
|
+
export abstract class AbstractSdk {
|
|
91
|
+
protected options: Options;
|
|
92
|
+
protected readonly _client: AxiosInstance;
|
|
93
|
+
protected readonly _logger: Logger;
|
|
94
|
+
protected constructor(options: Options);
|
|
95
|
+
abstract getAuthUrl(params: AuthorizationRequestParams): GetAuthURlResult;
|
|
96
|
+
abstract getTokens(params: AccessTokenRequest): AsyncResponse<TokenResponse>;
|
|
97
|
+
abstract refreshToken(params: RefreshTokenRequestParams): AsyncResponse<TokenResponse>;
|
|
98
|
+
fail(exc: AppHttpExceptionResponse): void;
|
|
99
|
+
}
|
|
100
|
+
export interface SyncConfigsMethod {
|
|
101
|
+
syncConfigs(userId: string): Promise<Connection[]>;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
104
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OAuthSdk = void 0;
|
|
7
|
+
const core_1 = require("@my-nestjs-kit/core");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const common_1 = require("@nestjs/common");
|
|
10
|
+
var OAuthSdk;
|
|
11
|
+
(function (OAuthSdk) {
|
|
12
|
+
let GrantType;
|
|
13
|
+
(function (GrantType) {
|
|
14
|
+
GrantType["AUTHORIZATION_CODE"] = "authorization_code";
|
|
15
|
+
GrantType["REFRESH_TOKEN"] = "refresh_token";
|
|
16
|
+
})(GrantType = OAuthSdk.GrantType || (OAuthSdk.GrantType = {}));
|
|
17
|
+
let ResponseType;
|
|
18
|
+
(function (ResponseType) {
|
|
19
|
+
ResponseType["CODE"] = "code";
|
|
20
|
+
})(ResponseType = OAuthSdk.ResponseType || (OAuthSdk.ResponseType = {}));
|
|
21
|
+
let TokenStatus;
|
|
22
|
+
(function (TokenStatus) {
|
|
23
|
+
TokenStatus["VALID"] = "valid";
|
|
24
|
+
TokenStatus["INVALID"] = "invalid";
|
|
25
|
+
})(TokenStatus = OAuthSdk.TokenStatus || (OAuthSdk.TokenStatus = {}));
|
|
26
|
+
function hasClient(cnf) {
|
|
27
|
+
return 'client' in cnf;
|
|
28
|
+
}
|
|
29
|
+
function hasConfig(cnf) {
|
|
30
|
+
return 'config' in cnf;
|
|
31
|
+
}
|
|
32
|
+
class AbstractSdk {
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.options = options;
|
|
35
|
+
this._logger = new common_1.Logger(this.constructor.name);
|
|
36
|
+
if (hasConfig(options)) {
|
|
37
|
+
this._client = axios_1.default.create(options.config);
|
|
38
|
+
this._logger.verbose('Sdk initialized with config');
|
|
39
|
+
}
|
|
40
|
+
if (hasClient(options)) {
|
|
41
|
+
this._client = options.client;
|
|
42
|
+
this._logger.verbose('Sdk initialized with client');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
fail(exc) {
|
|
46
|
+
throw new core_1.AppHttpException({
|
|
47
|
+
...exc,
|
|
48
|
+
meta: {
|
|
49
|
+
...exc.meta,
|
|
50
|
+
sdk: this.constructor.name,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
OAuthSdk.AbstractSdk = AbstractSdk;
|
|
56
|
+
})(OAuthSdk || (exports.OAuthSdk = OAuthSdk = {}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { JwtIssuerEnum, KeysOf, PartialRecord, PermissionHolderEnum } from '@my-nestjs-kit/core';
|
|
2
|
+
import { AuthConfigs, AuthConfigsItem, AuthModelConfig, AuthTokenType } from './types/auth.types';
|
|
3
|
+
import { Reflector } from '@nestjs/core';
|
|
4
|
+
export declare class AuthConfigsMetaStorage<Roles extends string = string, Session extends string = any, Action extends string = string> {
|
|
5
|
+
static KEY: string;
|
|
6
|
+
static IS_PUBLIC_KEY: string;
|
|
7
|
+
static IS_SUPER_ADMIN_KEY: string;
|
|
8
|
+
model?: PartialRecord<keyof typeof JwtIssuerEnum, boolean>;
|
|
9
|
+
tokenTypes?: PartialRecord<keyof typeof AuthTokenType, boolean>;
|
|
10
|
+
holder?: PartialRecord<keyof typeof PermissionHolderEnum, boolean>;
|
|
11
|
+
sessionFor?: Partial<Record<Session, boolean>>;
|
|
12
|
+
roleFor?: Partial<Record<Roles, boolean>>;
|
|
13
|
+
isOwnerAction?: boolean;
|
|
14
|
+
isSecureAction?: boolean;
|
|
15
|
+
isServerAction?: boolean;
|
|
16
|
+
modelsLists?: AuthConfigsItem<JwtIssuerEnum>;
|
|
17
|
+
models?: Partial<Record<JwtIssuerEnum, AuthModelConfig>>;
|
|
18
|
+
roles?: Roles[];
|
|
19
|
+
sessions?: Session[];
|
|
20
|
+
isPublic?: boolean;
|
|
21
|
+
actions?: Action[];
|
|
22
|
+
holders?: PartialRecord<'ignore' | 'white' | 'black', KeysOf<typeof PermissionHolderEnum>[]>;
|
|
23
|
+
holdersList?: KeysOf<typeof PermissionHolderEnum>[];
|
|
24
|
+
constructor(payload: AuthConfigs<Roles, Session, Action>);
|
|
25
|
+
}
|
|
26
|
+
export declare function getAuthParamsMetaStorage<Type extends {
|
|
27
|
+
type: string;
|
|
28
|
+
target: any;
|
|
29
|
+
}>(reflector: Reflector, ...list: Type[]): Record<Type["type"], AuthConfigsMetaStorage<string, any, string>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthParamsMetaStorage = exports.AuthConfigsMetaStorage = void 0;
|
|
4
|
+
const core_1 = require("@my-nestjs-kit/core");
|
|
5
|
+
class AuthConfigsMetaStorage {
|
|
6
|
+
constructor(payload) {
|
|
7
|
+
Object.assign(this, payload);
|
|
8
|
+
if (payload.holder) {
|
|
9
|
+
this.holdersList = (0, core_1.ObjectKeys)(payload?.holder);
|
|
10
|
+
this.holders = {
|
|
11
|
+
white: [],
|
|
12
|
+
black: [],
|
|
13
|
+
ignore: [],
|
|
14
|
+
};
|
|
15
|
+
this.holdersList.forEach((type) => {
|
|
16
|
+
if (payload.holder[type]) {
|
|
17
|
+
if (this.holders.white)
|
|
18
|
+
this.holders.white.push(type);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AuthConfigsMetaStorage = AuthConfigsMetaStorage;
|
|
25
|
+
AuthConfigsMetaStorage.KEY = 'auth_configs:meta_storage';
|
|
26
|
+
AuthConfigsMetaStorage.IS_PUBLIC_KEY = 'auth_configs:is_public';
|
|
27
|
+
AuthConfigsMetaStorage.IS_SUPER_ADMIN_KEY = 'auth_configs:is_super_admin';
|
|
28
|
+
function getAuthParamsMetaStorage(reflector, ...list) {
|
|
29
|
+
return list.reduce(() => {
|
|
30
|
+
return list.reduce((acc, { type, target }) => {
|
|
31
|
+
const meta = reflector.get(AuthConfigsMetaStorage.KEY, target);
|
|
32
|
+
return { ...acc, [type]: meta };
|
|
33
|
+
}, {});
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
exports.getAuthParamsMetaStorage = getAuthParamsMetaStorage;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RepoFindOptionsBase } from '@my-nestjs-kit/core';
|
|
2
|
+
import { PermissionCTX } from '@my-nestjs-kit/core';
|
|
3
|
+
import { AbstractAuthService, BaseAuthServiceMeta } from '../helper/base-auth-service.helper';
|
|
4
|
+
import { JwtAuthService } from '../jwt/jwt-auth.service';
|
|
5
|
+
import { JwtType } from '../jwt/types/enums';
|
|
6
|
+
import { AuthSessionBaseEntity } from '../entities/auth-session-base.entity';
|
|
7
|
+
import { AbstractAuthSessionRepoService } from './abstract-sessions-repo.service';
|
|
8
|
+
import { OAuth } from '../o-auth/o-auth.namespace';
|
|
9
|
+
export type JwtTokenPayloadBase<Access extends string = any, Role extends string = any, Holder extends string = any, Model extends string = any> = {
|
|
10
|
+
_id: string;
|
|
11
|
+
ip?: string;
|
|
12
|
+
role?: Role;
|
|
13
|
+
holder?: Holder;
|
|
14
|
+
model?: Model;
|
|
15
|
+
provider?: OAuth.ProviderType;
|
|
16
|
+
access?: Access;
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class AbstractAuthSessionsAuthService<Target extends AuthSessionBaseEntity, ReoSrv extends AbstractAuthSessionRepoService<Target> = AbstractAuthSessionRepoService<Target>, TokenPayload extends JwtTokenPayloadBase = JwtTokenPayloadBase> extends AbstractAuthService<Record<JwtType, TokenPayload>> {
|
|
19
|
+
protected readonly repoSrv: ReoSrv;
|
|
20
|
+
protected constructor(meta: BaseAuthServiceMeta | undefined, jwtService: JwtAuthService, repoSrv: ReoSrv);
|
|
21
|
+
abstract getAccessTokenPayload<Extra = any>(entity: Target, extra?: Extra): TokenPayload;
|
|
22
|
+
abstract getRefreshTokenPayload<Extra = any>(entity: Target, extra?: Extra): TokenPayload;
|
|
23
|
+
setAccessToken(entity: Target, payload: TokenPayload): Promise<Target>;
|
|
24
|
+
setRefreshToken(entity: Target, payload: TokenPayload): Promise<Target>;
|
|
25
|
+
setTokens<Extra = any>(entity: Target, extra?: Extra): Promise<Target>;
|
|
26
|
+
refreshToken(entity: Target, options?: RepoFindOptionsBase, rp?: PermissionCTX): Promise<Target>;
|
|
27
|
+
startWith<Extra = any>(entity: Target, extra?: Extra): Promise<Target>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAuthSessionsAuthService = void 0;
|
|
4
|
+
const base_auth_service_helper_1 = require("../helper/base-auth-service.helper");
|
|
5
|
+
const enums_1 = require("../jwt/types/enums");
|
|
6
|
+
class AbstractAuthSessionsAuthService extends base_auth_service_helper_1.AbstractAuthService {
|
|
7
|
+
constructor(meta, jwtService, repoSrv) {
|
|
8
|
+
super(meta ?? { jwtAudience: enums_1.JwtAudienceEnum.USER }, jwtService);
|
|
9
|
+
this.repoSrv = repoSrv;
|
|
10
|
+
}
|
|
11
|
+
async setAccessToken(entity, payload) {
|
|
12
|
+
entity.access_token = await this.signTokenAsync('ACCESS', this.getAccessTokenPayload(entity));
|
|
13
|
+
return entity;
|
|
14
|
+
}
|
|
15
|
+
async setRefreshToken(entity, payload) {
|
|
16
|
+
entity.refresh_token = await this.signTokenAsync('REFRESH', this.getRefreshTokenPayload(entity));
|
|
17
|
+
return entity;
|
|
18
|
+
}
|
|
19
|
+
async setTokens(entity, extra) {
|
|
20
|
+
await this.setAccessToken(entity, this.getAccessTokenPayload(entity, extra));
|
|
21
|
+
await this.setRefreshToken(entity, this.getRefreshTokenPayload(entity, extra));
|
|
22
|
+
return entity;
|
|
23
|
+
}
|
|
24
|
+
async refreshToken(entity, options, rp) {
|
|
25
|
+
const exist = await this.repoSrv._findOneOrFail({ _id: entity._id }, { credentials: true });
|
|
26
|
+
// if (exist.extId?.provider) {
|
|
27
|
+
// this.logger.debug(
|
|
28
|
+
// `Auth session has ext provider | ${exist.extId?.provider}`,
|
|
29
|
+
// );
|
|
30
|
+
// }
|
|
31
|
+
await this.setAccessToken(exist, this.getAccessTokenPayload(entity));
|
|
32
|
+
await this.repoSrv._repo.save(exist);
|
|
33
|
+
return exist;
|
|
34
|
+
}
|
|
35
|
+
async startWith(entity, extra) {
|
|
36
|
+
const started = await this.setTokens(entity, extra);
|
|
37
|
+
await this.repoSrv._repo.save(started);
|
|
38
|
+
return started;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.AbstractAuthSessionsAuthService = AbstractAuthSessionsAuthService;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FindOneParams } from '@my-nestjs-kit/core';
|
|
2
|
+
import { AbstractRepositoryService, BaseRepoServiceConfigs, RepoFindOptionsBase } from '@my-nestjs-kit/core';
|
|
3
|
+
import { AuthSessionBaseEntity } from '../entities/auth-session-base.entity';
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
|
+
export declare abstract class AbstractAuthSessionRepoService<Target extends AuthSessionBaseEntity, RepoFindOptionsType = any> extends AbstractRepositoryService<Target> {
|
|
6
|
+
protected constructor(configs: BaseRepoServiceConfigs<Target & {
|
|
7
|
+
path?: string;
|
|
8
|
+
}, RepoFindOptionsType & RepoFindOptionsBase>, dSource: DataSource);
|
|
9
|
+
abstract _findOneOrFail(queries: FindOneParams<{
|
|
10
|
+
_id?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
provider?: string;
|
|
13
|
+
}>['queries'], options?: FindOneParams['options']): Promise<Target>;
|
|
14
|
+
remove({ soft, ...input }: {
|
|
15
|
+
soft?: boolean;
|
|
16
|
+
} & ({
|
|
17
|
+
target: Target;
|
|
18
|
+
} | {
|
|
19
|
+
id: string;
|
|
20
|
+
}), canRemove?: () => void): Promise<{
|
|
21
|
+
result: boolean;
|
|
22
|
+
_id: string;
|
|
23
|
+
}>;
|
|
24
|
+
abstract findOne(...args: any[]): Promise<Target>;
|
|
25
|
+
abstract findOneOrFail(...args: any[]): Promise<Target>;
|
|
26
|
+
getOneById<Extra = any>(_id: string, options?: RepoFindOptionsBase, extra?: Extra): Promise<Target>;
|
|
27
|
+
getOneByIdOrFail<Extra = any>(_id: string, options?: RepoFindOptionsBase, extra?: Extra): Promise<Target>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAuthSessionRepoService = void 0;
|
|
4
|
+
const core_1 = require("@my-nestjs-kit/core");
|
|
5
|
+
class AbstractAuthSessionRepoService extends core_1.AbstractRepositoryService {
|
|
6
|
+
constructor(configs, dSource) {
|
|
7
|
+
super(configs, dSource);
|
|
8
|
+
}
|
|
9
|
+
async remove({ soft, ...input }, canRemove) {
|
|
10
|
+
const entity = 'id' in input
|
|
11
|
+
? await this._findOneOrFail({ _id: input.id })
|
|
12
|
+
: input.target;
|
|
13
|
+
const remover = () => {
|
|
14
|
+
if (soft === false) {
|
|
15
|
+
return this._repo.remove(entity);
|
|
16
|
+
}
|
|
17
|
+
return this._repo.softRemove(entity);
|
|
18
|
+
};
|
|
19
|
+
return { result: !!(await remover()), _id: entity._id };
|
|
20
|
+
}
|
|
21
|
+
getOneById(_id, options, extra) {
|
|
22
|
+
return this.findOne({ query: { _id }, queries: { _id } }, options, extra);
|
|
23
|
+
}
|
|
24
|
+
getOneByIdOrFail(_id, options, extra) {
|
|
25
|
+
return this.findOneOrFail({ query: { _id }, queries: { _id } }, options, extra);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.AbstractAuthSessionRepoService = AbstractAuthSessionRepoService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HasAuthParams } from './auth.types';
|
|
2
|
+
import type { PermissionCTX } from '@my-nestjs-kit/core';
|
|
3
|
+
import type { AppRequestTarget } from '@my-nestjs-kit/core';
|
|
4
|
+
import type { AuthSessionBaseEntity } from '../entities/auth-session-base.entity';
|
|
5
|
+
/**
|
|
6
|
+
* Request fields the auth guards fill in. Name kept from the ERP (ErpRequestTarget) so moved code compiles as-is;
|
|
7
|
+
* concrete session/connection entity types are narrowed by each service.
|
|
8
|
+
*/
|
|
9
|
+
export interface ErpRequestTarget extends AppRequestTarget, HasAuthParams {
|
|
10
|
+
session?: AuthSessionBaseEntity;
|
|
11
|
+
permission?: PermissionCTX;
|
|
12
|
+
/** resolved integration / oauth connections (`input`, `output`, `oauth`, `oauth_<provider>`, ...) */
|
|
13
|
+
connections?: Record<string, any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DeepPartial } from 'typeorm';
|
|
2
|
+
import type { AuthParams } from '../decorators/GetAuthParams.decorator';
|
|
3
|
+
import { JwtIssuerEnum, PermissionHolderEnum } from '@my-nestjs-kit/core';
|
|
4
|
+
import type { PermissionCTX } from '@my-nestjs-kit/core';
|
|
5
|
+
import { BooleanRecord } from '@my-nestjs-kit/core';
|
|
6
|
+
export declare enum AuthTokenType {
|
|
7
|
+
pToken = "pToken",
|
|
8
|
+
xToken = "xToken",
|
|
9
|
+
jwtErp = "jwtErp",
|
|
10
|
+
jwtCrm = "jwtCrm"
|
|
11
|
+
}
|
|
12
|
+
export interface HasRequestPermission extends HasAuthParams {
|
|
13
|
+
rp: PermissionCTX;
|
|
14
|
+
}
|
|
15
|
+
type FutureFlagName = 'Public' | 'Internal' | 'Secure' | 'Admin' | 'Server' | 'Owner' | 'Ai' | 'OwnerAction' | 'SecureAction' | 'ServerAction';
|
|
16
|
+
type FutureBoolFlags = BooleanRecord<`is${FutureFlagName}`>;
|
|
17
|
+
export interface IAuthConfigs<Roles extends string = string, Session extends string = string, Action extends string = string> extends FutureBoolFlags {
|
|
18
|
+
model?: BooleanRecord<keyof typeof JwtIssuerEnum>;
|
|
19
|
+
tokenTypes?: BooleanRecord<keyof typeof AuthTokenType>;
|
|
20
|
+
holder?: BooleanRecord<keyof typeof PermissionHolderEnum>;
|
|
21
|
+
sessionFor?: BooleanRecord<Session>;
|
|
22
|
+
roleFor?: BooleanRecord<Roles>;
|
|
23
|
+
modelsLists?: AuthConfigsItem<JwtIssuerEnum>;
|
|
24
|
+
models?: Partial<Record<JwtIssuerEnum, AuthModelConfig>>;
|
|
25
|
+
roles?: Roles[];
|
|
26
|
+
sessions?: Session[];
|
|
27
|
+
/** app-defined action names; narrow via `SetAuthConfig<Roles, Session, Action>` */
|
|
28
|
+
actions?: Action[];
|
|
29
|
+
}
|
|
30
|
+
export interface AuthModelConfig<Model = any> {
|
|
31
|
+
required?: boolean;
|
|
32
|
+
optional?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface AuthConfigsItem<T = any> {
|
|
35
|
+
whiteList?: T[];
|
|
36
|
+
blackList?: T[];
|
|
37
|
+
checkList?: T[];
|
|
38
|
+
}
|
|
39
|
+
export type AuthConfigs<Roles extends string = string, Session extends string = any, Action extends string = string> = DeepPartial<IAuthConfigs<Roles, Session, Action>>;
|
|
40
|
+
export interface HasAuthParams {
|
|
41
|
+
authParams?: AuthParams;
|
|
42
|
+
}
|
|
43
|
+
export {};
|