@flusys/nestjs-auth 7.0.2 → 7.1.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/README.md +67 -0
- package/cjs/config/auth.constants.js +8 -0
- package/cjs/config/event-actions.js +4 -2
- package/cjs/config/message-keys.js +27 -0
- package/cjs/controllers/index.js +2 -0
- package/cjs/controllers/social-auth-config.controller.js +107 -0
- package/cjs/controllers/social-auth.controller.js +175 -0
- package/cjs/controllers/social-auth.controller.spec.js +79 -0
- package/cjs/docs/auth-swagger.config.js +9 -1
- package/cjs/dtos/index.js +1 -0
- package/cjs/dtos/social-auth.dto.js +318 -0
- package/cjs/entities/index.js +3 -1
- package/cjs/entities/index.spec.js +12 -1
- package/cjs/entities/social-auth-config.entity.js +102 -0
- package/cjs/enums/index.js +1 -0
- package/cjs/enums/social-provider-type.enum.js +17 -0
- package/cjs/index.js +1 -0
- package/cjs/interfaces/index.js +1 -0
- package/cjs/interfaces/social-auth.interface.js +4 -0
- package/cjs/modules/auth.module.js +6 -0
- package/cjs/modules/auth.module.spec.js +15 -0
- package/cjs/providers/facebook.social-provider.js +73 -0
- package/cjs/providers/google.social-provider.js +68 -0
- package/cjs/providers/index.js +18 -0
- package/cjs/providers/linkedin.social-provider.js +66 -0
- package/cjs/providers/microsoft.social-provider.js +78 -0
- package/cjs/providers/oauth-http.util.js +107 -0
- package/cjs/providers/social-provider.registry.js +24 -0
- package/cjs/providers/social-provider.registry.spec.js +135 -0
- package/cjs/services/auth-config.service.js +3 -0
- package/cjs/services/auth-config.service.spec.js +3 -0
- package/cjs/services/auth-datasource.provider.js +4 -0
- package/cjs/services/auth-datasource.provider.spec.js +30 -0
- package/cjs/services/authentication.service.js +38 -8
- package/cjs/services/authentication.service.spec.js +58 -0
- package/cjs/services/index.js +2 -0
- package/cjs/services/social-auth-config.service.js +103 -0
- package/cjs/services/social-auth-config.service.spec.js +71 -0
- package/cjs/services/social-auth.service.js +310 -0
- package/cjs/services/social-auth.service.spec.js +310 -0
- package/config/auth.constants.d.ts +2 -0
- package/config/event-actions.d.ts +2 -0
- package/config/message-keys.d.ts +21 -0
- package/controllers/index.d.ts +2 -0
- package/controllers/social-auth-config.controller.d.ts +22 -0
- package/controllers/social-auth.controller.d.ts +11 -0
- package/dtos/index.d.ts +1 -0
- package/dtos/social-auth.dto.d.ts +42 -0
- package/entities/index.d.ts +3 -1
- package/entities/social-auth-config.entity.d.ts +9 -0
- package/enums/index.d.ts +1 -0
- package/enums/social-provider-type.enum.d.ts +6 -0
- package/fesm/config/auth.constants.js +3 -0
- package/fesm/config/event-actions.js +4 -2
- package/fesm/config/message-keys.js +21 -0
- package/fesm/controllers/index.js +2 -0
- package/fesm/controllers/social-auth-config.controller.js +97 -0
- package/fesm/controllers/social-auth.controller.js +165 -0
- package/fesm/controllers/social-auth.controller.spec.js +75 -0
- package/fesm/docs/auth-swagger.config.js +9 -1
- package/fesm/dtos/index.js +1 -0
- package/fesm/dtos/social-auth.dto.js +282 -0
- package/fesm/entities/index.js +4 -1
- package/fesm/entities/index.spec.js +12 -1
- package/fesm/entities/social-auth-config.entity.js +92 -0
- package/fesm/enums/index.js +1 -0
- package/fesm/enums/social-provider-type.enum.js +7 -0
- package/fesm/index.js +1 -0
- package/fesm/interfaces/index.js +1 -0
- package/fesm/interfaces/social-auth.interface.js +1 -0
- package/fesm/modules/auth.module.js +8 -2
- package/fesm/modules/auth.module.spec.js +17 -2
- package/fesm/providers/facebook.social-provider.js +63 -0
- package/fesm/providers/google.social-provider.js +58 -0
- package/fesm/providers/index.js +1 -0
- package/fesm/providers/linkedin.social-provider.js +56 -0
- package/fesm/providers/microsoft.social-provider.js +68 -0
- package/fesm/providers/oauth-http.util.js +77 -0
- package/fesm/providers/social-provider.registry.js +14 -0
- package/fesm/providers/social-provider.registry.spec.js +131 -0
- package/fesm/services/auth-config.service.js +3 -0
- package/fesm/services/auth-config.service.spec.js +3 -0
- package/fesm/services/auth-datasource.provider.js +4 -0
- package/fesm/services/auth-datasource.provider.spec.js +30 -0
- package/fesm/services/authentication.service.js +38 -8
- package/fesm/services/authentication.service.spec.js +58 -0
- package/fesm/services/index.js +2 -0
- package/fesm/services/social-auth-config.service.js +93 -0
- package/fesm/services/social-auth-config.service.spec.js +67 -0
- package/fesm/services/social-auth.service.js +300 -0
- package/fesm/services/social-auth.service.spec.js +265 -0
- package/index.d.ts +1 -0
- package/interfaces/index.d.ts +1 -0
- package/interfaces/social-auth.interface.d.ts +43 -0
- package/package.json +3 -3
- package/providers/facebook.social-provider.d.ts +10 -0
- package/providers/google.social-provider.d.ts +10 -0
- package/providers/index.d.ts +1 -0
- package/providers/linkedin.social-provider.d.ts +10 -0
- package/providers/microsoft.social-provider.d.ts +10 -0
- package/providers/oauth-http.util.d.ts +10 -0
- package/providers/social-provider.registry.d.ts +3 -0
- package/services/auth-config.service.d.ts +1 -0
- package/services/auth-datasource.provider.d.ts +1 -0
- package/services/authentication.service.d.ts +4 -0
- package/services/index.d.ts +2 -0
- package/services/social-auth-config.service.d.ts +21 -0
- package/services/social-auth.service.d.ts +24 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get CreateSocialAuthConfigDto () {
|
|
13
|
+
return CreateSocialAuthConfigDto;
|
|
14
|
+
},
|
|
15
|
+
get SocialAuthConfigResponseDto () {
|
|
16
|
+
return SocialAuthConfigResponseDto;
|
|
17
|
+
},
|
|
18
|
+
get SocialAuthorizeDto () {
|
|
19
|
+
return SocialAuthorizeDto;
|
|
20
|
+
},
|
|
21
|
+
get SocialAuthorizeResponseDto () {
|
|
22
|
+
return SocialAuthorizeResponseDto;
|
|
23
|
+
},
|
|
24
|
+
get SocialCallbackDto () {
|
|
25
|
+
return SocialCallbackDto;
|
|
26
|
+
},
|
|
27
|
+
get SocialProviderInfoDto () {
|
|
28
|
+
return SocialProviderInfoDto;
|
|
29
|
+
},
|
|
30
|
+
get SocialProvidersDto () {
|
|
31
|
+
return SocialProvidersDto;
|
|
32
|
+
},
|
|
33
|
+
get UpdateSocialAuthConfigDto () {
|
|
34
|
+
return UpdateSocialAuthConfigDto;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _dtos = require("@flusys/nestjs-shared/dtos");
|
|
38
|
+
const _swagger = require("@nestjs/swagger");
|
|
39
|
+
const _classtransformer = require("class-transformer");
|
|
40
|
+
const _classvalidator = require("class-validator");
|
|
41
|
+
const _socialprovidertypeenum = require("../enums/social-provider-type.enum");
|
|
42
|
+
function _define_property(obj, key, value) {
|
|
43
|
+
if (key in obj) {
|
|
44
|
+
Object.defineProperty(obj, key, {
|
|
45
|
+
value: value,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
obj[key] = value;
|
|
52
|
+
}
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
56
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
57
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
58
|
+
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;
|
|
59
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
60
|
+
}
|
|
61
|
+
function _ts_metadata(k, v) {
|
|
62
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
63
|
+
}
|
|
64
|
+
let CreateSocialAuthConfigDto = class CreateSocialAuthConfigDto {
|
|
65
|
+
constructor(){
|
|
66
|
+
_define_property(this, "provider", void 0);
|
|
67
|
+
_define_property(this, "isEnabled", void 0);
|
|
68
|
+
_define_property(this, "clientId", void 0);
|
|
69
|
+
_define_property(this, "clientSecret", void 0);
|
|
70
|
+
_define_property(this, "scopes", void 0);
|
|
71
|
+
_define_property(this, "extraConfig", void 0);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
_ts_decorate([
|
|
75
|
+
(0, _classtransformer.Expose)(),
|
|
76
|
+
(0, _swagger.ApiProperty)({
|
|
77
|
+
enum: _socialprovidertypeenum.SocialProviderTypeEnum,
|
|
78
|
+
example: _socialprovidertypeenum.SocialProviderTypeEnum.GOOGLE
|
|
79
|
+
}),
|
|
80
|
+
(0, _classvalidator.IsEnum)(_socialprovidertypeenum.SocialProviderTypeEnum),
|
|
81
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
82
|
+
_ts_metadata("design:type", typeof _socialprovidertypeenum.SocialProviderTypeEnum === "undefined" ? Object : _socialprovidertypeenum.SocialProviderTypeEnum)
|
|
83
|
+
], CreateSocialAuthConfigDto.prototype, "provider", void 0);
|
|
84
|
+
_ts_decorate([
|
|
85
|
+
(0, _classtransformer.Expose)(),
|
|
86
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
87
|
+
example: true,
|
|
88
|
+
description: 'Offer this provider on the login page'
|
|
89
|
+
}),
|
|
90
|
+
(0, _classvalidator.IsBoolean)(),
|
|
91
|
+
(0, _classvalidator.IsOptional)(),
|
|
92
|
+
_ts_metadata("design:type", Boolean)
|
|
93
|
+
], CreateSocialAuthConfigDto.prototype, "isEnabled", void 0);
|
|
94
|
+
_ts_decorate([
|
|
95
|
+
(0, _classtransformer.Expose)(),
|
|
96
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
97
|
+
example: '1234567890-abc.apps.googleusercontent.com'
|
|
98
|
+
}),
|
|
99
|
+
(0, _classvalidator.IsString)(),
|
|
100
|
+
(0, _classvalidator.IsOptional)(),
|
|
101
|
+
(0, _classvalidator.MaxLength)(512),
|
|
102
|
+
_ts_metadata("design:type", String)
|
|
103
|
+
], CreateSocialAuthConfigDto.prototype, "clientId", void 0);
|
|
104
|
+
_ts_decorate([
|
|
105
|
+
(0, _classtransformer.Expose)(),
|
|
106
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
107
|
+
example: 'GOCSPX-secret-value'
|
|
108
|
+
}),
|
|
109
|
+
(0, _classvalidator.IsString)(),
|
|
110
|
+
(0, _classvalidator.IsOptional)(),
|
|
111
|
+
_ts_metadata("design:type", String)
|
|
112
|
+
], CreateSocialAuthConfigDto.prototype, "clientSecret", void 0);
|
|
113
|
+
_ts_decorate([
|
|
114
|
+
(0, _classtransformer.Expose)(),
|
|
115
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
116
|
+
type: [
|
|
117
|
+
String
|
|
118
|
+
],
|
|
119
|
+
example: [
|
|
120
|
+
'openid',
|
|
121
|
+
'email',
|
|
122
|
+
'profile'
|
|
123
|
+
],
|
|
124
|
+
description: "Overrides the provider's default scopes when set"
|
|
125
|
+
}),
|
|
126
|
+
(0, _classvalidator.IsArray)(),
|
|
127
|
+
(0, _classvalidator.IsString)({
|
|
128
|
+
each: true
|
|
129
|
+
}),
|
|
130
|
+
(0, _classvalidator.ArrayMaxSize)(30),
|
|
131
|
+
(0, _classvalidator.IsOptional)(),
|
|
132
|
+
_ts_metadata("design:type", Array)
|
|
133
|
+
], CreateSocialAuthConfigDto.prototype, "scopes", void 0);
|
|
134
|
+
_ts_decorate([
|
|
135
|
+
(0, _classtransformer.Expose)(),
|
|
136
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
137
|
+
type: 'object',
|
|
138
|
+
additionalProperties: true,
|
|
139
|
+
description: "Provider specific extras, such as Microsoft's tenantId",
|
|
140
|
+
example: {
|
|
141
|
+
tenantId: 'common'
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
(0, _classvalidator.IsObject)(),
|
|
145
|
+
(0, _classvalidator.IsOptional)(),
|
|
146
|
+
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
147
|
+
], CreateSocialAuthConfigDto.prototype, "extraConfig", void 0);
|
|
148
|
+
let UpdateSocialAuthConfigDto = class UpdateSocialAuthConfigDto extends (0, _swagger.PartialType)(CreateSocialAuthConfigDto) {
|
|
149
|
+
constructor(...args){
|
|
150
|
+
super(...args), _define_property(this, "id", void 0);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
_ts_decorate([
|
|
154
|
+
(0, _classtransformer.Expose)(),
|
|
155
|
+
(0, _swagger.ApiProperty)({
|
|
156
|
+
example: '123e4567-e89b-12d3-a456-426614174000'
|
|
157
|
+
}),
|
|
158
|
+
(0, _classvalidator.IsString)(),
|
|
159
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
160
|
+
_ts_metadata("design:type", String)
|
|
161
|
+
], UpdateSocialAuthConfigDto.prototype, "id", void 0);
|
|
162
|
+
let SocialAuthConfigResponseDto = class SocialAuthConfigResponseDto extends _dtos.IdentityResponseDto {
|
|
163
|
+
constructor(...args){
|
|
164
|
+
super(...args), _define_property(this, "provider", void 0), _define_property(this, "isEnabled", void 0), _define_property(this, "clientId", void 0), _define_property(this, "hasClientSecret", void 0), _define_property(this, "scopes", void 0), _define_property(this, "extraConfig", void 0);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
_ts_decorate([
|
|
168
|
+
(0, _swagger.ApiProperty)({
|
|
169
|
+
enum: _socialprovidertypeenum.SocialProviderTypeEnum,
|
|
170
|
+
example: _socialprovidertypeenum.SocialProviderTypeEnum.GOOGLE
|
|
171
|
+
}),
|
|
172
|
+
(0, _classtransformer.Expose)(),
|
|
173
|
+
_ts_metadata("design:type", typeof _socialprovidertypeenum.SocialProviderTypeEnum === "undefined" ? Object : _socialprovidertypeenum.SocialProviderTypeEnum)
|
|
174
|
+
], SocialAuthConfigResponseDto.prototype, "provider", void 0);
|
|
175
|
+
_ts_decorate([
|
|
176
|
+
(0, _swagger.ApiProperty)({
|
|
177
|
+
example: true
|
|
178
|
+
}),
|
|
179
|
+
(0, _classtransformer.Expose)(),
|
|
180
|
+
_ts_metadata("design:type", Boolean)
|
|
181
|
+
], SocialAuthConfigResponseDto.prototype, "isEnabled", void 0);
|
|
182
|
+
_ts_decorate([
|
|
183
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
184
|
+
nullable: true
|
|
185
|
+
}),
|
|
186
|
+
(0, _classtransformer.Expose)(),
|
|
187
|
+
_ts_metadata("design:type", Object)
|
|
188
|
+
], SocialAuthConfigResponseDto.prototype, "clientId", void 0);
|
|
189
|
+
_ts_decorate([
|
|
190
|
+
(0, _swagger.ApiProperty)({
|
|
191
|
+
description: 'Whether a client secret is currently stored for this provider'
|
|
192
|
+
}),
|
|
193
|
+
(0, _classtransformer.Expose)(),
|
|
194
|
+
(0, _classtransformer.Transform)(({ obj })=>!!obj.clientSecret),
|
|
195
|
+
_ts_metadata("design:type", Boolean)
|
|
196
|
+
], SocialAuthConfigResponseDto.prototype, "hasClientSecret", void 0);
|
|
197
|
+
_ts_decorate([
|
|
198
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
199
|
+
type: [
|
|
200
|
+
String
|
|
201
|
+
],
|
|
202
|
+
nullable: true
|
|
203
|
+
}),
|
|
204
|
+
(0, _classtransformer.Expose)(),
|
|
205
|
+
_ts_metadata("design:type", Object)
|
|
206
|
+
], SocialAuthConfigResponseDto.prototype, "scopes", void 0);
|
|
207
|
+
_ts_decorate([
|
|
208
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
209
|
+
type: 'object',
|
|
210
|
+
additionalProperties: true,
|
|
211
|
+
nullable: true
|
|
212
|
+
}),
|
|
213
|
+
(0, _classtransformer.Expose)(),
|
|
214
|
+
_ts_metadata("design:type", Object)
|
|
215
|
+
], SocialAuthConfigResponseDto.prototype, "extraConfig", void 0);
|
|
216
|
+
let SocialProviderInfoDto = class SocialProviderInfoDto {
|
|
217
|
+
constructor(){
|
|
218
|
+
_define_property(this, "provider", void 0);
|
|
219
|
+
_define_property(this, "redirectUri", void 0);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
_ts_decorate([
|
|
223
|
+
(0, _swagger.ApiProperty)({
|
|
224
|
+
enum: _socialprovidertypeenum.SocialProviderTypeEnum,
|
|
225
|
+
example: _socialprovidertypeenum.SocialProviderTypeEnum.GOOGLE
|
|
226
|
+
}),
|
|
227
|
+
(0, _classtransformer.Expose)(),
|
|
228
|
+
_ts_metadata("design:type", typeof _socialprovidertypeenum.SocialProviderTypeEnum === "undefined" ? Object : _socialprovidertypeenum.SocialProviderTypeEnum)
|
|
229
|
+
], SocialProviderInfoDto.prototype, "provider", void 0);
|
|
230
|
+
_ts_decorate([
|
|
231
|
+
(0, _swagger.ApiProperty)({
|
|
232
|
+
example: 'http://localhost:2001/auth/social/callback'
|
|
233
|
+
}),
|
|
234
|
+
(0, _classtransformer.Expose)(),
|
|
235
|
+
_ts_metadata("design:type", String)
|
|
236
|
+
], SocialProviderInfoDto.prototype, "redirectUri", void 0);
|
|
237
|
+
let SocialProvidersDto = class SocialProvidersDto {
|
|
238
|
+
constructor(){
|
|
239
|
+
_define_property(this, "redirectUri", void 0);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
_ts_decorate([
|
|
243
|
+
(0, _swagger.ApiProperty)({
|
|
244
|
+
example: 'http://localhost:2001/auth/social/callback',
|
|
245
|
+
description: 'Must match the URI registered with the provider and the one sent on callback'
|
|
246
|
+
}),
|
|
247
|
+
(0, _classvalidator.IsUrl)({
|
|
248
|
+
require_tld: false
|
|
249
|
+
}),
|
|
250
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
251
|
+
(0, _classvalidator.MaxLength)(2048),
|
|
252
|
+
_ts_metadata("design:type", String)
|
|
253
|
+
], SocialProvidersDto.prototype, "redirectUri", void 0);
|
|
254
|
+
let SocialAuthorizeDto = class SocialAuthorizeDto extends SocialProvidersDto {
|
|
255
|
+
constructor(...args){
|
|
256
|
+
super(...args), _define_property(this, "provider", void 0);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
_ts_decorate([
|
|
260
|
+
(0, _swagger.ApiProperty)({
|
|
261
|
+
enum: _socialprovidertypeenum.SocialProviderTypeEnum,
|
|
262
|
+
example: _socialprovidertypeenum.SocialProviderTypeEnum.GOOGLE
|
|
263
|
+
}),
|
|
264
|
+
(0, _classvalidator.IsEnum)(_socialprovidertypeenum.SocialProviderTypeEnum),
|
|
265
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
266
|
+
_ts_metadata("design:type", typeof _socialprovidertypeenum.SocialProviderTypeEnum === "undefined" ? Object : _socialprovidertypeenum.SocialProviderTypeEnum)
|
|
267
|
+
], SocialAuthorizeDto.prototype, "provider", void 0);
|
|
268
|
+
let SocialAuthorizeResponseDto = class SocialAuthorizeResponseDto {
|
|
269
|
+
constructor(){
|
|
270
|
+
_define_property(this, "provider", void 0);
|
|
271
|
+
_define_property(this, "authorizationUrl", void 0);
|
|
272
|
+
_define_property(this, "state", void 0);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
_ts_decorate([
|
|
276
|
+
(0, _swagger.ApiProperty)({
|
|
277
|
+
enum: _socialprovidertypeenum.SocialProviderTypeEnum
|
|
278
|
+
}),
|
|
279
|
+
(0, _classtransformer.Expose)(),
|
|
280
|
+
_ts_metadata("design:type", typeof _socialprovidertypeenum.SocialProviderTypeEnum === "undefined" ? Object : _socialprovidertypeenum.SocialProviderTypeEnum)
|
|
281
|
+
], SocialAuthorizeResponseDto.prototype, "provider", void 0);
|
|
282
|
+
_ts_decorate([
|
|
283
|
+
(0, _swagger.ApiProperty)({
|
|
284
|
+
description: "The provider's consent screen to redirect the browser to"
|
|
285
|
+
}),
|
|
286
|
+
(0, _classtransformer.Expose)(),
|
|
287
|
+
_ts_metadata("design:type", String)
|
|
288
|
+
], SocialAuthorizeResponseDto.prototype, "authorizationUrl", void 0);
|
|
289
|
+
_ts_decorate([
|
|
290
|
+
(0, _swagger.ApiProperty)({
|
|
291
|
+
description: 'Opaque CSRF token, echoed back by the provider'
|
|
292
|
+
}),
|
|
293
|
+
(0, _classtransformer.Expose)(),
|
|
294
|
+
_ts_metadata("design:type", String)
|
|
295
|
+
], SocialAuthorizeResponseDto.prototype, "state", void 0);
|
|
296
|
+
let SocialCallbackDto = class SocialCallbackDto extends SocialProvidersDto {
|
|
297
|
+
constructor(...args){
|
|
298
|
+
super(...args), _define_property(this, "code", void 0), _define_property(this, "state", void 0);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
_ts_decorate([
|
|
302
|
+
(0, _swagger.ApiProperty)({
|
|
303
|
+
description: 'Authorization code returned by the provider'
|
|
304
|
+
}),
|
|
305
|
+
(0, _classvalidator.IsString)(),
|
|
306
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
307
|
+
(0, _classvalidator.MaxLength)(4096),
|
|
308
|
+
_ts_metadata("design:type", String)
|
|
309
|
+
], SocialCallbackDto.prototype, "code", void 0);
|
|
310
|
+
_ts_decorate([
|
|
311
|
+
(0, _swagger.ApiProperty)({
|
|
312
|
+
description: 'The state issued by /auth/social/authorize'
|
|
313
|
+
}),
|
|
314
|
+
(0, _classvalidator.IsString)(),
|
|
315
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
316
|
+
(0, _classvalidator.MaxLength)(128),
|
|
317
|
+
_ts_metadata("design:type", String)
|
|
318
|
+
], SocialCallbackDto.prototype, "state", void 0);
|
package/cjs/entities/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const _appuserentity = _export_star(require("./app-user.entity"), exports);
|
|
|
23
23
|
const _companybranchentity = _export_star(require("./company-branch.entity"), exports);
|
|
24
24
|
const _companyentity = _export_star(require("./company.entity"), exports);
|
|
25
25
|
const _pendingregistrationentity = _export_star(require("./pending-registration.entity"), exports);
|
|
26
|
+
const _socialauthconfigentity = _export_star(require("./social-auth-config.entity"), exports);
|
|
26
27
|
const _usercompanypermissionentity = require("./user-company-permission.entity");
|
|
27
28
|
const _usertokenentity = _export_star(require("./user-token.entity"), exports);
|
|
28
29
|
function _export_star(from, to) {
|
|
@@ -40,7 +41,8 @@ function _export_star(from, to) {
|
|
|
40
41
|
}
|
|
41
42
|
const BaseEntities = [
|
|
42
43
|
_appuserentity.AppUser,
|
|
43
|
-
_usertokenentity.UserToken
|
|
44
|
+
_usertokenentity.UserToken,
|
|
45
|
+
_socialauthconfigentity.SocialAuthConfig
|
|
44
46
|
];
|
|
45
47
|
const EmailEntities = [
|
|
46
48
|
_pendingregistrationentity.PendingRegistration
|
|
@@ -6,6 +6,7 @@ const _index = require("./index");
|
|
|
6
6
|
const _appuserentity = require("./app-user.entity");
|
|
7
7
|
const _usertokenentity = require("./user-token.entity");
|
|
8
8
|
const _pendingregistrationentity = require("./pending-registration.entity");
|
|
9
|
+
const _socialauthconfigentity = require("./social-auth-config.entity");
|
|
9
10
|
const _companyentity = require("./company.entity");
|
|
10
11
|
const _companybranchentity = require("./company-branch.entity");
|
|
11
12
|
const _usercompanypermissionentity = require("./user-company-permission.entity");
|
|
@@ -20,6 +21,15 @@ describe('getAuthEntitiesByConfig', ()=>{
|
|
|
20
21
|
_usertokenentity.UserToken
|
|
21
22
|
]));
|
|
22
23
|
});
|
|
24
|
+
it('should always include the social sign-in config entity, which no flag gates', ()=>{
|
|
25
|
+
const entities = (0, _index.getAuthEntitiesByConfig)({
|
|
26
|
+
enableCompanyFeature: false,
|
|
27
|
+
enableEmailVerification: false
|
|
28
|
+
});
|
|
29
|
+
expect(entities).toEqual(expect.arrayContaining([
|
|
30
|
+
_socialauthconfigentity.SocialAuthConfig
|
|
31
|
+
]));
|
|
32
|
+
});
|
|
23
33
|
it('should include PendingRegistration when email verification is enabled', ()=>{
|
|
24
34
|
const entities = (0, _index.getAuthEntitiesByConfig)({
|
|
25
35
|
enableEmailVerification: true
|
|
@@ -60,10 +70,11 @@ describe('getAuthEntitiesByConfig', ()=>{
|
|
|
60
70
|
enableCompanyFeature: true,
|
|
61
71
|
enableEmailVerification: true
|
|
62
72
|
});
|
|
63
|
-
expect(entities).toHaveLength(
|
|
73
|
+
expect(entities).toHaveLength(7);
|
|
64
74
|
expect(entities).toEqual(expect.arrayContaining([
|
|
65
75
|
_appuserentity.AppUser,
|
|
66
76
|
_usertokenentity.UserToken,
|
|
77
|
+
_socialauthconfigentity.SocialAuthConfig,
|
|
67
78
|
_pendingregistrationentity.PendingRegistration,
|
|
68
79
|
_companyentity.Company,
|
|
69
80
|
_companybranchentity.CompanyBranch,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SocialAuthConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SocialAuthConfig;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
12
|
+
const _entities = require("@flusys/nestjs-shared/entities");
|
|
13
|
+
const _typeorm = require("typeorm");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
28
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
+
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;
|
|
31
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
+
}
|
|
33
|
+
function _ts_metadata(k, v) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
+
}
|
|
36
|
+
let SocialAuthConfig = class SocialAuthConfig extends _entities.Identity {
|
|
37
|
+
constructor(...args){
|
|
38
|
+
super(...args), _define_property(this, "provider", void 0), _define_property(this, "isEnabled", void 0), _define_property(this, "clientId", void 0), _define_property(this, "clientSecret", void 0), _define_property(this, "scopes", void 0), _define_property(this, "extraConfig", void 0);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
_ts_decorate([
|
|
42
|
+
(0, _typeorm.Column)({
|
|
43
|
+
type: 'varchar',
|
|
44
|
+
length: 32,
|
|
45
|
+
nullable: false
|
|
46
|
+
}),
|
|
47
|
+
_ts_metadata("design:type", String)
|
|
48
|
+
], SocialAuthConfig.prototype, "provider", void 0);
|
|
49
|
+
_ts_decorate([
|
|
50
|
+
(0, _typeorm.Column)({
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
default: false,
|
|
53
|
+
name: 'is_enabled'
|
|
54
|
+
}),
|
|
55
|
+
_ts_metadata("design:type", Boolean)
|
|
56
|
+
], SocialAuthConfig.prototype, "isEnabled", void 0);
|
|
57
|
+
_ts_decorate([
|
|
58
|
+
(0, _typeorm.Column)({
|
|
59
|
+
type: 'varchar',
|
|
60
|
+
length: 512,
|
|
61
|
+
nullable: true,
|
|
62
|
+
name: 'client_id'
|
|
63
|
+
}),
|
|
64
|
+
_ts_metadata("design:type", Object)
|
|
65
|
+
], SocialAuthConfig.prototype, "clientId", void 0);
|
|
66
|
+
_ts_decorate([
|
|
67
|
+
(0, _typeorm.Column)({
|
|
68
|
+
type: 'text',
|
|
69
|
+
nullable: true,
|
|
70
|
+
name: 'client_secret'
|
|
71
|
+
}),
|
|
72
|
+
_ts_metadata("design:type", Object)
|
|
73
|
+
], SocialAuthConfig.prototype, "clientSecret", void 0);
|
|
74
|
+
_ts_decorate([
|
|
75
|
+
(0, _typeorm.Column)({
|
|
76
|
+
type: 'simple-array',
|
|
77
|
+
nullable: true
|
|
78
|
+
}),
|
|
79
|
+
_ts_metadata("design:type", Object)
|
|
80
|
+
], SocialAuthConfig.prototype, "scopes", void 0);
|
|
81
|
+
_ts_decorate([
|
|
82
|
+
(0, _typeorm.Column)({
|
|
83
|
+
type: (0, _nestjsshared.getJsonColumnType)(),
|
|
84
|
+
nullable: true,
|
|
85
|
+
name: 'extra_config'
|
|
86
|
+
}),
|
|
87
|
+
_ts_metadata("design:type", Object)
|
|
88
|
+
], SocialAuthConfig.prototype, "extraConfig", void 0);
|
|
89
|
+
SocialAuthConfig = _ts_decorate([
|
|
90
|
+
(0, _typeorm.Entity)({
|
|
91
|
+
name: 'social_auth_config'
|
|
92
|
+
}),
|
|
93
|
+
(0, _typeorm.Index)('IDX_social_auth_config_provider', [
|
|
94
|
+
'provider'
|
|
95
|
+
], {
|
|
96
|
+
unique: true,
|
|
97
|
+
where: '"deleted_at" IS NULL'
|
|
98
|
+
}),
|
|
99
|
+
(0, _typeorm.Index)([
|
|
100
|
+
'isEnabled'
|
|
101
|
+
])
|
|
102
|
+
], SocialAuthConfig);
|
package/cjs/enums/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
_export_star(require("./social-provider-type.enum"), exports);
|
|
5
6
|
_export_star(require("./user-org-permission-type.enum"), exports);
|
|
6
7
|
function _export_star(from, to) {
|
|
7
8
|
Object.keys(from).forEach(function(k) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SocialProviderTypeEnum", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SocialProviderTypeEnum;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var SocialProviderTypeEnum = /*#__PURE__*/ function(SocialProviderTypeEnum) {
|
|
12
|
+
SocialProviderTypeEnum["GOOGLE"] = "google";
|
|
13
|
+
SocialProviderTypeEnum["FACEBOOK"] = "facebook";
|
|
14
|
+
SocialProviderTypeEnum["LINKEDIN"] = "linkedin";
|
|
15
|
+
SocialProviderTypeEnum["MICROSOFT"] = "microsoft";
|
|
16
|
+
return SocialProviderTypeEnum;
|
|
17
|
+
}({});
|
package/cjs/index.js
CHANGED
|
@@ -12,6 +12,7 @@ _export_star(require("./helpers"), exports);
|
|
|
12
12
|
_export_star(require("./interceptors"), exports);
|
|
13
13
|
_export_star(require("./interfaces"), exports);
|
|
14
14
|
_export_star(require("./modules"), exports);
|
|
15
|
+
_export_star(require("./providers"), exports);
|
|
15
16
|
_export_star(require("./services"), exports);
|
|
16
17
|
_export_star(require("./strategies/jwt.strategy"), exports);
|
|
17
18
|
function _export_star(from, to) {
|
package/cjs/interfaces/index.js
CHANGED
|
@@ -6,6 +6,7 @@ _export_star(require("./authentication.interface"), exports);
|
|
|
6
6
|
_export_star(require("./auth-email-provider.interface"), exports);
|
|
7
7
|
_export_star(require("./company-branch.interface"), exports);
|
|
8
8
|
_export_star(require("./company.interface"), exports);
|
|
9
|
+
_export_star(require("./social-auth.interface"), exports);
|
|
9
10
|
_export_star(require("./user.interface"), exports);
|
|
10
11
|
_export_star(require("./user-enricher.interface"), exports);
|
|
11
12
|
_export_star(require("./auth-module-options.interface"), exports);
|
|
@@ -84,6 +84,8 @@ let AuthModule = class AuthModule {
|
|
|
84
84
|
if (!includeController) return [];
|
|
85
85
|
const controllers = [
|
|
86
86
|
_controllers.AuthenticationController,
|
|
87
|
+
_controllers.SocialAuthController,
|
|
88
|
+
_controllers.SocialAuthConfigController,
|
|
87
89
|
_controllers.UserController
|
|
88
90
|
];
|
|
89
91
|
if (flags.enableEmailVerification) {
|
|
@@ -101,6 +103,8 @@ let AuthModule = class AuthModule {
|
|
|
101
103
|
_jwtstrategy.JwtStrategy,
|
|
102
104
|
_guards.JwtAuthGuard,
|
|
103
105
|
_services.AuthenticationService,
|
|
106
|
+
_services.SocialAuthService,
|
|
107
|
+
_services.SocialAuthConfigService,
|
|
104
108
|
_settokeninterceptor.SetToken,
|
|
105
109
|
_cleartokeninterceptor.ClearToken,
|
|
106
110
|
_services.UserService,
|
|
@@ -123,6 +127,8 @@ let AuthModule = class AuthModule {
|
|
|
123
127
|
_jwtstrategy.JwtStrategy,
|
|
124
128
|
_guards.JwtAuthGuard,
|
|
125
129
|
_services.AuthenticationService,
|
|
130
|
+
_services.SocialAuthService,
|
|
131
|
+
_services.SocialAuthConfigService,
|
|
126
132
|
_services.UserService
|
|
127
133
|
];
|
|
128
134
|
if (flags.enableEmailVerification) {
|
|
@@ -34,11 +34,26 @@ describe('AuthModule', ()=>{
|
|
|
34
34
|
expect(dynamicModule.global).toBe(false);
|
|
35
35
|
expect(dynamicModule.controllers).toEqual([
|
|
36
36
|
_controllers.AuthenticationController,
|
|
37
|
+
_controllers.SocialAuthController,
|
|
38
|
+
_controllers.SocialAuthConfigController,
|
|
37
39
|
_controllers.UserController
|
|
38
40
|
]);
|
|
39
41
|
expect(providerTokens(dynamicModule.providers)).not.toContain(_services.AuthEmailService);
|
|
40
42
|
expect(providerTokens(dynamicModule.providers)).not.toContain(_services.CompanyService);
|
|
41
43
|
});
|
|
44
|
+
it('should always register social sign-in, whatever the feature flags say', ()=>{
|
|
45
|
+
const dynamicModule = _authmodule.AuthModule.forRoot({
|
|
46
|
+
bootstrapAppConfig: {
|
|
47
|
+
enableCompanyFeature: false
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
expect(dynamicModule.controllers).toContain(_controllers.SocialAuthController);
|
|
51
|
+
expect(dynamicModule.controllers).toContain(_controllers.SocialAuthConfigController);
|
|
52
|
+
expect(providerTokens(dynamicModule.providers)).toContain(_services.SocialAuthService);
|
|
53
|
+
expect(providerTokens(dynamicModule.providers)).toContain(_services.SocialAuthConfigService);
|
|
54
|
+
expect(dynamicModule.exports).toContain(_services.SocialAuthService);
|
|
55
|
+
expect(dynamicModule.exports).toContain(_services.SocialAuthConfigService);
|
|
56
|
+
});
|
|
42
57
|
it('should respect global: true', ()=>{
|
|
43
58
|
const dynamicModule = _authmodule.AuthModule.forRoot({
|
|
44
59
|
global: true
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "facebookSocialProvider", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return facebookSocialProvider;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _socialprovidertypeenum = require("../enums/social-provider-type.enum");
|
|
12
|
+
const _oauthhttputil = require("./oauth-http.util");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
const GRAPH_VERSION = 'v21.0';
|
|
27
|
+
const AUTHORIZE_URL = `https://www.facebook.com/${GRAPH_VERSION}/dialog/oauth`;
|
|
28
|
+
const TOKEN_URL = `https://graph.facebook.com/${GRAPH_VERSION}/oauth/access_token`;
|
|
29
|
+
const PROFILE_URL = `https://graph.facebook.com/${GRAPH_VERSION}/me?fields=id,name,email,picture.type(large)`;
|
|
30
|
+
function readAvatarUrl(profile) {
|
|
31
|
+
const picture = profile['picture'];
|
|
32
|
+
if (typeof picture !== 'object' || picture === null) return null;
|
|
33
|
+
const data = picture['data'];
|
|
34
|
+
if (typeof data !== 'object' || data === null) return null;
|
|
35
|
+
return (0, _oauthhttputil.readString)(data, 'url');
|
|
36
|
+
}
|
|
37
|
+
let FacebookSocialProvider = class FacebookSocialProvider {
|
|
38
|
+
buildAuthorizationUrl(credentials, state) {
|
|
39
|
+
const query = (0, _oauthhttputil.buildQuery)({
|
|
40
|
+
client_id: credentials.clientId,
|
|
41
|
+
redirect_uri: credentials.redirectUri,
|
|
42
|
+
response_type: 'code',
|
|
43
|
+
scope: (0, _oauthhttputil.resolveScopes)(credentials, this.defaultScopes, ','),
|
|
44
|
+
state
|
|
45
|
+
});
|
|
46
|
+
return `${AUTHORIZE_URL}?${query}`;
|
|
47
|
+
}
|
|
48
|
+
async fetchProfile(credentials, code) {
|
|
49
|
+
const token = await (0, _oauthhttputil.postForm)(this.provider, TOKEN_URL, {
|
|
50
|
+
code,
|
|
51
|
+
client_id: credentials.clientId,
|
|
52
|
+
client_secret: credentials.clientSecret,
|
|
53
|
+
redirect_uri: credentials.redirectUri
|
|
54
|
+
});
|
|
55
|
+
const profile = await (0, _oauthhttputil.getJson)(this.provider, PROFILE_URL, (0, _oauthhttputil.readAccessToken)(this.provider, token));
|
|
56
|
+
const email = (0, _oauthhttputil.readString)(profile, 'email');
|
|
57
|
+
return {
|
|
58
|
+
providerUserId: (0, _oauthhttputil.readString)(profile, 'id') ?? '',
|
|
59
|
+
email,
|
|
60
|
+
emailVerified: !!email,
|
|
61
|
+
name: (0, _oauthhttputil.readString)(profile, 'name'),
|
|
62
|
+
avatarUrl: readAvatarUrl(profile)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
constructor(){
|
|
66
|
+
_define_property(this, "provider", _socialprovidertypeenum.SocialProviderTypeEnum.FACEBOOK);
|
|
67
|
+
_define_property(this, "defaultScopes", [
|
|
68
|
+
'email',
|
|
69
|
+
'public_profile'
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const facebookSocialProvider = new FacebookSocialProvider();
|