@smartsoft001/auth-domain 1.1.91 → 2.69.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/.eslintrc.json +26 -0
- package/README.md +161 -2
- package/jest.config.ts +26 -0
- package/package.json +3 -32
- package/project.json +44 -0
- package/src/index.ts +9 -0
- package/src/lib/entities/user.entity.ts +34 -0
- package/src/lib/feature-create-token/interfaces.ts +51 -0
- package/src/lib/feature-create-token/token-payload.provider.ts +17 -0
- package/src/lib/feature-create-token/token-user.provider.ts +14 -0
- package/src/lib/feature-create-token/token-validation.provider.ts +13 -0
- package/src/lib/feature-create-token/token.config.ts +8 -0
- package/src/lib/feature-create-token/token.factory.spec.ts +194 -0
- package/src/lib/feature-create-token/token.factory.ts +200 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +20 -0
- package/src/index.d.ts +0 -6
- package/src/index.js +0 -15
- package/src/index.js.map +0 -1
- package/src/lib/entities/index.js +0 -5
- package/src/lib/entities/index.js.map +0 -1
- package/src/lib/entities/user.entity.d.ts +0 -13
- package/src/lib/entities/user.entity.js +0 -47
- package/src/lib/entities/user.entity.js.map +0 -1
- package/src/lib/feature-create-token/index.js +0 -10
- package/src/lib/feature-create-token/index.js.map +0 -1
- package/src/lib/feature-create-token/interfaces.d.ts +0 -39
- package/src/lib/feature-create-token/interfaces.js +0 -3
- package/src/lib/feature-create-token/interfaces.js.map +0 -1
- package/src/lib/feature-create-token/token-payload.provider.d.ts +0 -11
- package/src/lib/feature-create-token/token-payload.provider.js +0 -8
- package/src/lib/feature-create-token/token-payload.provider.js.map +0 -1
- package/src/lib/feature-create-token/token-user.provider.d.ts +0 -7
- package/src/lib/feature-create-token/token-user.provider.js +0 -8
- package/src/lib/feature-create-token/token-user.provider.js.map +0 -1
- package/src/lib/feature-create-token/token-validation.provider.d.ts +0 -10
- package/src/lib/feature-create-token/token-validation.provider.js +0 -8
- package/src/lib/feature-create-token/token-validation.provider.js.map +0 -1
- package/src/lib/feature-create-token/token.config.d.ts +0 -5
- package/src/lib/feature-create-token/token.config.js +0 -14
- package/src/lib/feature-create-token/token.config.js.map +0 -1
- package/src/lib/feature-create-token/token.factory.d.ts +0 -39
- package/src/lib/feature-create-token/token.factory.js +0 -158
- package/src/lib/feature-create-token/token.factory.js.map +0 -1
- package/test-setup.js +0 -1
- package/test-setup.js.map +0 -1
- /package/src/lib/entities/{index.d.ts → index.ts} +0 -0
- /package/src/lib/feature-create-token/{index.d.ts → index.ts} +0 -0
- /package/{test-setup.d.ts → test-setup.ts} +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { JwtService } from '@nestjs/jwt';
|
|
3
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
4
|
+
import { Request } from 'express';
|
|
5
|
+
import { Guid } from 'guid-typescript';
|
|
6
|
+
import { Repository } from 'typeorm';
|
|
7
|
+
|
|
8
|
+
import { DomainValidationError, IFactory } from '@smartsoft001/domain-core';
|
|
9
|
+
import { FbService } from '@smartsoft001/fb';
|
|
10
|
+
import { GoogleService } from '@smartsoft001/google';
|
|
11
|
+
import { PasswordService } from '@smartsoft001/utils';
|
|
12
|
+
|
|
13
|
+
import { User } from '../entities';
|
|
14
|
+
import { IAuthToken, IAuthTokenRequest } from './interfaces';
|
|
15
|
+
import { ITokenPayloadProvider } from './token-payload.provider';
|
|
16
|
+
import { ITokenUserProvider } from './token-user.provider';
|
|
17
|
+
import { ITokenValidationProvider } from './token-validation.provider';
|
|
18
|
+
import { TokenConfig } from './token.config';
|
|
19
|
+
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class TokenFactory
|
|
22
|
+
implements
|
|
23
|
+
IFactory<
|
|
24
|
+
IAuthToken,
|
|
25
|
+
{
|
|
26
|
+
httpReq?: Request;
|
|
27
|
+
request: IAuthTokenRequest;
|
|
28
|
+
payloadProvider?: ITokenPayloadProvider;
|
|
29
|
+
validationProvider?: ITokenValidationProvider;
|
|
30
|
+
userProvider?: ITokenUserProvider;
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
{
|
|
34
|
+
private _invalidUsernameOrPasswordMessage = 'Invalid username or password';
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
private config: TokenConfig,
|
|
38
|
+
@InjectRepository(User) private repository: Repository<User>,
|
|
39
|
+
private jwtService: JwtService,
|
|
40
|
+
private fbService: FbService,
|
|
41
|
+
private googleService: GoogleService,
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
static getQuery(
|
|
45
|
+
config: IAuthTokenRequest,
|
|
46
|
+
customProvider = false,
|
|
47
|
+
): Partial<User> {
|
|
48
|
+
switch (config.grant_type) {
|
|
49
|
+
case 'fb':
|
|
50
|
+
return { facebookUserId: config.fb_user_id };
|
|
51
|
+
case 'google':
|
|
52
|
+
return { googleUserId: config.google_user_id };
|
|
53
|
+
case 'password':
|
|
54
|
+
return { username: config.username };
|
|
55
|
+
case 'refresh_token':
|
|
56
|
+
return { authRefreshToken: config.refresh_token };
|
|
57
|
+
default:
|
|
58
|
+
if (!customProvider) {
|
|
59
|
+
throw new DomainValidationError('Invalid grand type');
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static checkDisabled(user: User) {
|
|
66
|
+
if (user.disabled) throw new DomainValidationError('user disabled');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async create(options: {
|
|
70
|
+
httpReq?: Request;
|
|
71
|
+
request: IAuthTokenRequest;
|
|
72
|
+
payloadProvider?: ITokenPayloadProvider;
|
|
73
|
+
validationProvider?: ITokenValidationProvider;
|
|
74
|
+
userProvider?: ITokenUserProvider;
|
|
75
|
+
}): Promise<IAuthToken> {
|
|
76
|
+
if (options.request.grant_type === 'fb') {
|
|
77
|
+
options.request.fb_user_id = await this.fbService.getUserId(
|
|
78
|
+
options.request.fb_token,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (options.request.grant_type === 'google') {
|
|
83
|
+
options.request.google_user_id = await this.googleService.getUserId(
|
|
84
|
+
options.request.google_token,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.valid(options.request);
|
|
89
|
+
|
|
90
|
+
const query = TokenFactory.getQuery(
|
|
91
|
+
options.request,
|
|
92
|
+
!!options.userProvider,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const user = options.userProvider
|
|
96
|
+
? await options.userProvider.get(query, options.request, options.httpReq)
|
|
97
|
+
: await this.repository.findOne(query as any);
|
|
98
|
+
|
|
99
|
+
if (!options.validationProvider || !options.validationProvider.replace) {
|
|
100
|
+
this.checkUser(options.request, user);
|
|
101
|
+
TokenFactory.checkDisabled(user);
|
|
102
|
+
await this.checkPassword(options.request, user);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (options.validationProvider) {
|
|
106
|
+
await options.validationProvider.check({
|
|
107
|
+
request: options.request,
|
|
108
|
+
user,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const refreshToken = Guid.raw();
|
|
113
|
+
await this.repository.update(
|
|
114
|
+
{
|
|
115
|
+
...query,
|
|
116
|
+
disabled: { $ne: true },
|
|
117
|
+
} as any,
|
|
118
|
+
{
|
|
119
|
+
lastLoginDate: new Date(),
|
|
120
|
+
authRefreshToken: refreshToken,
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const payload = {
|
|
125
|
+
permissions: user.permissions,
|
|
126
|
+
scope: options.request.scope,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (options.payloadProvider) {
|
|
130
|
+
await options.payloadProvider.change(payload, {
|
|
131
|
+
user,
|
|
132
|
+
request: options.request,
|
|
133
|
+
httpReq: options.httpReq,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
expired_in: this.config.expiredIn,
|
|
139
|
+
token_type: 'bearer',
|
|
140
|
+
access_token: this.jwtService.sign(payload, {
|
|
141
|
+
expiresIn: this.config.expiredIn,
|
|
142
|
+
subject: user.username,
|
|
143
|
+
}),
|
|
144
|
+
refresh_token: refreshToken,
|
|
145
|
+
username: user.username,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private checkUser(config: IAuthTokenRequest, user: User): void {
|
|
150
|
+
if (!user)
|
|
151
|
+
throw new DomainValidationError(
|
|
152
|
+
config.grant_type === 'password'
|
|
153
|
+
? this._invalidUsernameOrPasswordMessage
|
|
154
|
+
: 'Invalid token',
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private async checkPassword(
|
|
159
|
+
config: IAuthTokenRequest,
|
|
160
|
+
user: User,
|
|
161
|
+
): Promise<void> {
|
|
162
|
+
if (
|
|
163
|
+
config.grant_type === 'password' &&
|
|
164
|
+
!(await PasswordService.compare(config.password, user.password))
|
|
165
|
+
)
|
|
166
|
+
throw new DomainValidationError(this._invalidUsernameOrPasswordMessage);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private valid(req: NonNullable<IAuthTokenRequest>): void {
|
|
170
|
+
if (!req) throw new DomainValidationError('config is empty');
|
|
171
|
+
if (!req.grant_type) throw new DomainValidationError('grant_type is empty');
|
|
172
|
+
|
|
173
|
+
// password
|
|
174
|
+
if (req.grant_type === 'password') {
|
|
175
|
+
if (!req.username) throw new DomainValidationError('username is empty');
|
|
176
|
+
if (!req.password) throw new DomainValidationError('password is empty');
|
|
177
|
+
if (!req.client_id) throw new DomainValidationError('client_id is empty');
|
|
178
|
+
if (!this.config.clients.some((c) => c === req.client_id))
|
|
179
|
+
throw new DomainValidationError('client_id is incorrect');
|
|
180
|
+
|
|
181
|
+
// refres token
|
|
182
|
+
} else if (req.grant_type === 'refresh_token') {
|
|
183
|
+
if (!req.refresh_token)
|
|
184
|
+
throw new DomainValidationError('refresh_token is empty');
|
|
185
|
+
|
|
186
|
+
// fb token
|
|
187
|
+
} else if (req.grant_type === 'fb') {
|
|
188
|
+
if (!req.fb_token) throw new DomainValidationError('fb_token is empty');
|
|
189
|
+
|
|
190
|
+
if (!req.fb_user_id)
|
|
191
|
+
throw new DomainValidationError('fb_user_id is empty');
|
|
192
|
+
} else if (req.grant_type === 'google') {
|
|
193
|
+
if (!req.google_token)
|
|
194
|
+
throw new DomainValidationError('google_token is empty');
|
|
195
|
+
|
|
196
|
+
if (!req.google_user_id)
|
|
197
|
+
throw new DomainValidationError('google_user_id is empty');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"**/*.spec.ts",
|
|
10
|
+
"**/*.test.ts",
|
|
11
|
+
"**/*.spec.tsx",
|
|
12
|
+
"**/*.test.tsx",
|
|
13
|
+
"**/*.spec.js",
|
|
14
|
+
"**/*.test.js",
|
|
15
|
+
"**/*.spec.jsx",
|
|
16
|
+
"**/*.test.jsx",
|
|
17
|
+
"**/*.d.ts",
|
|
18
|
+
"jest.config.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/src/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { TokenFactory } from "./lib/feature-create-token/token.factory";
|
|
2
|
-
import { User } from "./lib/entities/user.entity";
|
|
3
|
-
export * from './lib/entities';
|
|
4
|
-
export * from './lib/feature-create-token';
|
|
5
|
-
export declare const DOMAIN_SERVICES: (typeof TokenFactory)[];
|
|
6
|
-
export declare const ENTITIES: (typeof User)[];
|
package/src/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENTITIES = exports.DOMAIN_SERVICES = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const token_factory_1 = require("./lib/feature-create-token/token.factory");
|
|
6
|
-
const user_entity_1 = require("./lib/entities/user.entity");
|
|
7
|
-
tslib_1.__exportStar(require("./lib/entities"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./lib/feature-create-token"), exports);
|
|
9
|
-
exports.DOMAIN_SERVICES = [
|
|
10
|
-
token_factory_1.TokenFactory
|
|
11
|
-
];
|
|
12
|
-
exports.ENTITIES = [
|
|
13
|
-
user_entity_1.User
|
|
14
|
-
];
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/domain/src/index.ts"],"names":[],"mappings":";;;;AAAA,4EAAsE;AACtE,4DAAgD;AAEhD,yDAA+B;AAC/B,qEAA2C;AAE9B,QAAA,eAAe,GAAG;IAC3B,4BAAY;CACf,CAAC;AAEW,QAAA,QAAQ,GAAG;IACpB,kBAAI;CACP,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/entities/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IEntity } from "@smartsoft001/domain-core";
|
|
2
|
-
import { IUser, IUserCredentials } from "@smartsoft001/users";
|
|
3
|
-
export declare class User implements IEntity<string>, IUser, IUserCredentials {
|
|
4
|
-
id: string;
|
|
5
|
-
permissions: Array<string>;
|
|
6
|
-
username: string;
|
|
7
|
-
password: string;
|
|
8
|
-
disabled: boolean;
|
|
9
|
-
lastLoginDate: Date;
|
|
10
|
-
authRefreshToken: string;
|
|
11
|
-
facebookUserId?: string;
|
|
12
|
-
googleUserId?: string;
|
|
13
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.User = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const typeorm_1 = require("typeorm");
|
|
6
|
-
let User = exports.User = class User {
|
|
7
|
-
};
|
|
8
|
-
tslib_1.__decorate([
|
|
9
|
-
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
10
|
-
tslib_1.__metadata("design:type", String)
|
|
11
|
-
], User.prototype, "id", void 0);
|
|
12
|
-
tslib_1.__decorate([
|
|
13
|
-
(0, typeorm_1.Column)("permissions"),
|
|
14
|
-
tslib_1.__metadata("design:type", Array)
|
|
15
|
-
], User.prototype, "permissions", void 0);
|
|
16
|
-
tslib_1.__decorate([
|
|
17
|
-
(0, typeorm_1.Column)("username"),
|
|
18
|
-
tslib_1.__metadata("design:type", String)
|
|
19
|
-
], User.prototype, "username", void 0);
|
|
20
|
-
tslib_1.__decorate([
|
|
21
|
-
(0, typeorm_1.Column)("password"),
|
|
22
|
-
tslib_1.__metadata("design:type", String)
|
|
23
|
-
], User.prototype, "password", void 0);
|
|
24
|
-
tslib_1.__decorate([
|
|
25
|
-
(0, typeorm_1.Column)("disabled"),
|
|
26
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
27
|
-
], User.prototype, "disabled", void 0);
|
|
28
|
-
tslib_1.__decorate([
|
|
29
|
-
(0, typeorm_1.Column)("lastLoginDate"),
|
|
30
|
-
tslib_1.__metadata("design:type", Date)
|
|
31
|
-
], User.prototype, "lastLoginDate", void 0);
|
|
32
|
-
tslib_1.__decorate([
|
|
33
|
-
(0, typeorm_1.Column)("authRefreshToken"),
|
|
34
|
-
tslib_1.__metadata("design:type", String)
|
|
35
|
-
], User.prototype, "authRefreshToken", void 0);
|
|
36
|
-
tslib_1.__decorate([
|
|
37
|
-
(0, typeorm_1.Column)("facebookUserId"),
|
|
38
|
-
tslib_1.__metadata("design:type", String)
|
|
39
|
-
], User.prototype, "facebookUserId", void 0);
|
|
40
|
-
tslib_1.__decorate([
|
|
41
|
-
(0, typeorm_1.Column)("googleUserId"),
|
|
42
|
-
tslib_1.__metadata("design:type", String)
|
|
43
|
-
], User.prototype, "googleUserId", void 0);
|
|
44
|
-
exports.User = User = tslib_1.__decorate([
|
|
45
|
-
(0, typeorm_1.Entity)('users')
|
|
46
|
-
], User);
|
|
47
|
-
//# sourceMappingURL=user.entity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/entities/user.entity.ts"],"names":[],"mappings":";;;;AAAA,qCAA+D;AAMxD,IAAM,IAAI,kBAAV,MAAM,IAAI;CA6BhB,CAAA;AA1BG;IADC,IAAA,gCAAsB,GAAE;;gCACd;AAGX;IADC,IAAA,gBAAM,EAAC,aAAa,CAAC;sCACT,KAAK;yCAAS;AAG3B;IADC,IAAA,gBAAM,EAAC,UAAU,CAAC;;sCACF;AAGjB;IADC,IAAA,gBAAM,EAAC,UAAU,CAAC;;sCACF;AAGjB;IADC,IAAA,gBAAM,EAAC,UAAU,CAAC;;sCACD;AAGlB;IADC,IAAA,gBAAM,EAAC,eAAe,CAAC;sCACT,IAAI;2CAAC;AAGpB;IADC,IAAA,gBAAM,EAAC,kBAAkB,CAAC;;8CACF;AAGzB;IADC,IAAA,gBAAM,EAAC,gBAAgB,CAAC;;4CACD;AAGxB;IADC,IAAA,gBAAM,EAAC,cAAc,CAAC;;0CACD;eA3Bb,IAAI;IADhB,IAAA,gBAAM,EAAC,OAAO,CAAC;GACH,IAAI,CA6BhB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./interfaces"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./token.factory"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./token.config"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./token-payload.provider"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./token-validation.provider"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./token-user.provider"), exports);
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,0DAAgC;AAChC,yDAA+B;AAC/B,mEAAyC;AACzC,sEAA4C;AAC5C,gEAAsC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { IUserCredentials } from "@smartsoft001/users";
|
|
2
|
-
export type IAuthTokenRequest = IAuthTokenRequestPassword | IAuthTokenRequestRefreshToken | IAuthTokenRequestCustom | IAuthTokenRequestFb | IAuthTokenRequestGoogle;
|
|
3
|
-
export interface IAuthTokenRequestFb extends IUserCredentials {
|
|
4
|
-
grant_type: "fb";
|
|
5
|
-
fb_token: string;
|
|
6
|
-
fb_user_id?: string;
|
|
7
|
-
scope?: string;
|
|
8
|
-
client_id: string;
|
|
9
|
-
}
|
|
10
|
-
export interface IAuthTokenRequestGoogle extends IUserCredentials {
|
|
11
|
-
grant_type: "google";
|
|
12
|
-
google_token: string;
|
|
13
|
-
google_user_id?: string;
|
|
14
|
-
scope?: string;
|
|
15
|
-
client_id: string;
|
|
16
|
-
}
|
|
17
|
-
export interface IAuthTokenRequestPassword extends IUserCredentials {
|
|
18
|
-
grant_type: "password";
|
|
19
|
-
username: string;
|
|
20
|
-
password: string;
|
|
21
|
-
scope?: string;
|
|
22
|
-
client_id: string;
|
|
23
|
-
}
|
|
24
|
-
export interface IAuthTokenRequestRefreshToken {
|
|
25
|
-
grant_type: "refresh_token";
|
|
26
|
-
refresh_token: string;
|
|
27
|
-
scope?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface IAuthToken {
|
|
30
|
-
access_token: string;
|
|
31
|
-
refresh_token: string;
|
|
32
|
-
expired_in: number;
|
|
33
|
-
token_type: 'bearer';
|
|
34
|
-
username?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface IAuthTokenRequestCustom {
|
|
37
|
-
grant_type: string;
|
|
38
|
-
[key: string]: string;
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import { IAuthTokenRequest } from "./interfaces";
|
|
3
|
-
import { User } from "../entities/user.entity";
|
|
4
|
-
export declare const AUTH_TOKEN_PAYLOAD_PROVIDER = "AUTH_TOKEN_PAYLOAD_PROVIDER";
|
|
5
|
-
export declare abstract class ITokenPayloadProvider {
|
|
6
|
-
abstract change(basePayload: any, data: {
|
|
7
|
-
request?: IAuthTokenRequest;
|
|
8
|
-
user?: User;
|
|
9
|
-
httpReq?: Request;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ITokenPayloadProvider = exports.AUTH_TOKEN_PAYLOAD_PROVIDER = void 0;
|
|
4
|
-
exports.AUTH_TOKEN_PAYLOAD_PROVIDER = "AUTH_TOKEN_PAYLOAD_PROVIDER";
|
|
5
|
-
class ITokenPayloadProvider {
|
|
6
|
-
}
|
|
7
|
-
exports.ITokenPayloadProvider = ITokenPayloadProvider;
|
|
8
|
-
//# sourceMappingURL=token-payload.provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-payload.provider.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/token-payload.provider.ts"],"names":[],"mappings":";;;AAKa,QAAA,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE,MAAsB,qBAAqB;CAS1C;AATD,sDASC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import { User } from "../entities/user.entity";
|
|
3
|
-
import { IAuthTokenRequest } from "./interfaces";
|
|
4
|
-
export declare const AUTH_TOKEN_USER_PROVIDER = "AUTH_TOKEN_USER_PROVIDER";
|
|
5
|
-
export declare abstract class ITokenUserProvider {
|
|
6
|
-
abstract get(baseQuery: Partial<User>, request: IAuthTokenRequest, httpReq?: Request): Promise<User>;
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ITokenUserProvider = exports.AUTH_TOKEN_USER_PROVIDER = void 0;
|
|
4
|
-
exports.AUTH_TOKEN_USER_PROVIDER = "AUTH_TOKEN_USER_PROVIDER";
|
|
5
|
-
class ITokenUserProvider {
|
|
6
|
-
}
|
|
7
|
-
exports.ITokenUserProvider = ITokenUserProvider;
|
|
8
|
-
//# sourceMappingURL=token-user.provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-user.provider.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/token-user.provider.ts"],"names":[],"mappings":";;;AAKa,QAAA,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE,MAAsB,kBAAkB;CAEvC;AAFD,gDAEC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IAuthTokenRequest } from "./interfaces";
|
|
2
|
-
import { User } from "../entities/user.entity";
|
|
3
|
-
export declare const AUTH_TOKEN_VALIDATION_PROVIDER = "AUTH_TOKEN_VALIDATION_PROVIDER";
|
|
4
|
-
export declare abstract class ITokenValidationProvider {
|
|
5
|
-
abstract replace?: boolean;
|
|
6
|
-
abstract check(data: {
|
|
7
|
-
request?: IAuthTokenRequest;
|
|
8
|
-
user?: User;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ITokenValidationProvider = exports.AUTH_TOKEN_VALIDATION_PROVIDER = void 0;
|
|
4
|
-
exports.AUTH_TOKEN_VALIDATION_PROVIDER = "AUTH_TOKEN_VALIDATION_PROVIDER";
|
|
5
|
-
class ITokenValidationProvider {
|
|
6
|
-
}
|
|
7
|
-
exports.ITokenValidationProvider = ITokenValidationProvider;
|
|
8
|
-
//# sourceMappingURL=token-validation.provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-validation.provider.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/token-validation.provider.ts"],"names":[],"mappings":";;;AAGa,QAAA,8BAA8B,GAAG,gCAAgC,CAAC;AAE/E,MAAsB,wBAAwB;CAS7C;AATD,4DASC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenConfig = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
let TokenConfig = exports.TokenConfig = class TokenConfig {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.clients = [];
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
exports.TokenConfig = TokenConfig = tslib_1.__decorate([
|
|
12
|
-
(0, common_1.Injectable)()
|
|
13
|
-
], TokenConfig);
|
|
14
|
-
//# sourceMappingURL=token.config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token.config.js","sourceRoot":"","sources":["../../../../../../../libs/auth/domain/src/lib/feature-create-token/token.config.ts"],"names":[],"mappings":";;;;AAAA,2CAA0C;AAGnC,IAAM,WAAW,yBAAjB,MAAM,WAAW;IAAjB;QAEH,YAAO,GAAkB,EAAE,CAAC;IAEhC,CAAC;CAAA,CAAA;sBAJY,WAAW;IADvB,IAAA,mBAAU,GAAE;GACA,WAAW,CAIvB"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Repository } from "typeorm";
|
|
2
|
-
import { JwtService } from "@nestjs/jwt";
|
|
3
|
-
import { Request } from "express";
|
|
4
|
-
import { IFactory } from "@smartsoft001/domain-core";
|
|
5
|
-
import { FbService } from "@smartsoft001/fb";
|
|
6
|
-
import { GoogleService } from "@smartsoft001/google";
|
|
7
|
-
import { User } from "../entities/user.entity";
|
|
8
|
-
import { TokenConfig } from "./token.config";
|
|
9
|
-
import { IAuthToken, IAuthTokenRequest } from "./interfaces";
|
|
10
|
-
import { ITokenPayloadProvider } from "./token-payload.provider";
|
|
11
|
-
import { ITokenValidationProvider } from "./token-validation.provider";
|
|
12
|
-
import { ITokenUserProvider } from "./token-user.provider";
|
|
13
|
-
export declare class TokenFactory implements IFactory<IAuthToken, {
|
|
14
|
-
httpReq?: Request;
|
|
15
|
-
request: IAuthTokenRequest;
|
|
16
|
-
payloadProvider?: ITokenPayloadProvider;
|
|
17
|
-
validationProvider?: ITokenValidationProvider;
|
|
18
|
-
userProvider?: ITokenUserProvider;
|
|
19
|
-
}> {
|
|
20
|
-
private config;
|
|
21
|
-
private repository;
|
|
22
|
-
private jwtService;
|
|
23
|
-
private fbService;
|
|
24
|
-
private googleService;
|
|
25
|
-
private _invalidUsernameOrPasswordMessage;
|
|
26
|
-
constructor(config: TokenConfig, repository: Repository<User>, jwtService: JwtService, fbService: FbService, googleService: GoogleService);
|
|
27
|
-
static getQuery(config: IAuthTokenRequest, customProvider?: boolean): Partial<User>;
|
|
28
|
-
static checkDisabled(user: User): void;
|
|
29
|
-
create(options: {
|
|
30
|
-
httpReq?: Request;
|
|
31
|
-
request: IAuthTokenRequest;
|
|
32
|
-
payloadProvider?: ITokenPayloadProvider;
|
|
33
|
-
validationProvider?: ITokenValidationProvider;
|
|
34
|
-
userProvider?: ITokenUserProvider;
|
|
35
|
-
}): Promise<IAuthToken>;
|
|
36
|
-
private checkUser;
|
|
37
|
-
private checkPassword;
|
|
38
|
-
private valid;
|
|
39
|
-
}
|