@tc-libs/authentication 1.15.0 → 1.17.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/package.json +3 -3
- package/src/authentication.module.options.d.ts +10 -0
- package/src/guards/apple/auth.apple-oauth.guard.d.ts +5 -0
- package/src/guards/apple/auth.apple-oauth.guard.js +19 -0
- package/src/guards/apple/auth.apple-oauth.guard.js.map +1 -0
- package/src/guards/apple/auth.apple-oauth.strategy.d.ts +21 -0
- package/src/guards/apple/auth.apple-oauth.strategy.js +56 -0
- package/src/guards/apple/auth.apple-oauth.strategy.js.map +1 -0
- package/src/guards/google-oauth/auth.google-oauth.strategy.d.ts +9 -10
- package/src/guards/google-oauth/auth.google-oauth.strategy.js +32 -0
- package/src/guards/google-oauth/auth.google-oauth.strategy.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/authentication",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/errors": "1.
|
|
6
|
-
"@tc-libs/helper": "1.
|
|
5
|
+
"@tc-libs/errors": "1.17.0",
|
|
6
|
+
"@tc-libs/helper": "1.17.0"
|
|
7
7
|
},
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"main": "./src/index.js",
|
|
@@ -11,6 +11,16 @@ export interface AuthenticationModuleOptions {
|
|
|
11
11
|
clientSecret: string;
|
|
12
12
|
callbackURL: string;
|
|
13
13
|
scope: string[];
|
|
14
|
+
getBirthday: boolean;
|
|
15
|
+
getPhoneNumber: boolean;
|
|
16
|
+
};
|
|
17
|
+
apple: {
|
|
18
|
+
clientID: string;
|
|
19
|
+
teamID: string;
|
|
20
|
+
keyID: string;
|
|
21
|
+
privateKeyString: string;
|
|
22
|
+
callbackURL: string;
|
|
23
|
+
scope: string[];
|
|
14
24
|
};
|
|
15
25
|
auth: {
|
|
16
26
|
prefixAuthorization: string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppleOAuthGuard = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const passport_1 = require("@nestjs/passport");
|
|
7
|
+
let AppleOAuthGuard = class AppleOAuthGuard extends (0, passport_1.AuthGuard)('apple') {
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
accessType: 'offline',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.AppleOAuthGuard = AppleOAuthGuard;
|
|
15
|
+
exports.AppleOAuthGuard = AppleOAuthGuard = tslib_1.__decorate([
|
|
16
|
+
(0, common_1.Injectable)(),
|
|
17
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
18
|
+
], AppleOAuthGuard);
|
|
19
|
+
//# sourceMappingURL=auth.apple-oauth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.apple-oauth.guard.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/apple/auth.apple-oauth.guard.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,IAAA,oBAAS,EAAC,OAAO,CAAC;IACrD;QACE,KAAK,CAAC;YACJ,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AANY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;;GACA,eAAe,CAM3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JwtService } from '@nestjs/jwt';
|
|
2
|
+
import { AuthenticationModuleOptions } from '../../authentication.module.options';
|
|
3
|
+
declare const AppleStrategy_base: new (...args: [options: import("passport-apple").AuthenticateOptionsWithRequest] | [options: import("passport-apple").AuthenticateOptions]) => import("passport-apple") & {
|
|
4
|
+
validate(...args: any[]): unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare class AppleStrategy extends AppleStrategy_base {
|
|
7
|
+
readonly _options: AuthenticationModuleOptions;
|
|
8
|
+
private readonly _jwt;
|
|
9
|
+
constructor(_options: AuthenticationModuleOptions, _jwt: JwtService);
|
|
10
|
+
validate(req: any, accessToken: string, refreshToken: string, idToken: string, profile: any): Promise<{
|
|
11
|
+
provider: string;
|
|
12
|
+
providerId: string;
|
|
13
|
+
email: any;
|
|
14
|
+
firstName: string | null;
|
|
15
|
+
lastName: string | null;
|
|
16
|
+
idToken: string;
|
|
17
|
+
accessToken: string;
|
|
18
|
+
refreshToken: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppleStrategy = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
7
|
+
const passport_1 = require("@nestjs/passport");
|
|
8
|
+
const passport_apple_1 = require("passport-apple");
|
|
9
|
+
const authentication_module_options_1 = require("../../authentication.module.options");
|
|
10
|
+
let AppleStrategy = class AppleStrategy extends (0, passport_1.PassportStrategy)(passport_apple_1.Strategy, 'apple') {
|
|
11
|
+
constructor(_options, _jwt) {
|
|
12
|
+
super({
|
|
13
|
+
clientID: _options.apple.clientID,
|
|
14
|
+
teamID: _options.apple.teamID,
|
|
15
|
+
callbackURL: _options.apple.callbackURL,
|
|
16
|
+
keyID: _options.apple.keyID,
|
|
17
|
+
privateKeyString: _options.apple.privateKeyString,
|
|
18
|
+
scope: _options.apple.scope,
|
|
19
|
+
passReqToCallback: true,
|
|
20
|
+
});
|
|
21
|
+
this._options = _options;
|
|
22
|
+
this._jwt = _jwt;
|
|
23
|
+
}
|
|
24
|
+
async validate(req, accessToken, refreshToken, idToken, profile) {
|
|
25
|
+
const claims = this._jwt.decode(idToken) || {};
|
|
26
|
+
const appleId = claims.sub;
|
|
27
|
+
const email = claims.email ?? null;
|
|
28
|
+
let firstName = null;
|
|
29
|
+
let lastName = null;
|
|
30
|
+
try {
|
|
31
|
+
const userRaw = req.body?.user ? JSON.parse(req.body.user) : null;
|
|
32
|
+
firstName = userRaw?.name?.firstName ?? null;
|
|
33
|
+
lastName = userRaw?.name?.lastName ?? null;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
provider: 'apple',
|
|
40
|
+
providerId: appleId,
|
|
41
|
+
email,
|
|
42
|
+
firstName,
|
|
43
|
+
lastName,
|
|
44
|
+
idToken,
|
|
45
|
+
accessToken,
|
|
46
|
+
refreshToken,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.AppleStrategy = AppleStrategy;
|
|
51
|
+
exports.AppleStrategy = AppleStrategy = tslib_1.__decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
53
|
+
tslib_1.__param(0, (0, common_1.Inject)(authentication_module_options_1.AUTHENTICATION_CONFIG_OPTIONS)),
|
|
54
|
+
tslib_1.__metadata("design:paramtypes", [Object, jwt_1.JwtService])
|
|
55
|
+
], AppleStrategy);
|
|
56
|
+
//# sourceMappingURL=auth.apple-oauth.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.apple-oauth.strategy.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/apple/auth.apple-oauth.strategy.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,qCAAyC;AACzC,+CAAoD;AACpD,mDAA0C;AAC1C,uFAG6C;AAGtC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,IAA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AAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,OAAO;YACjB,UAAU,EAAE,OAAO;YACnB,KAAK;YACL,SAAS;YACT,QAAQ;YACR,OAAO;YACP,WAAW;YACX,YAAY;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AAjDY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAGR,mBAAA,IAAA,eAAM,EAAC,6DAA6B,CAAC,CAAA;qDAEf,gBAAU;GAJxB,aAAa,CAiDzB"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { Profile, Strategy } from 'passport-google-oauth20';
|
|
2
2
|
import { AuthenticationModuleOptions } from '../../authentication.module.options';
|
|
3
|
+
export interface IBirthday {
|
|
4
|
+
day?: number;
|
|
5
|
+
month?: number;
|
|
6
|
+
year?: number;
|
|
7
|
+
date?: Date;
|
|
8
|
+
}
|
|
3
9
|
declare const GoogleStrategy_base: new (...args: [options: import("passport-google-oauth20").StrategyOptionsWithRequest] | [options: import("passport-google-oauth20").StrategyOptions] | [options: import("passport-google-oauth20").StrategyOptions] | [options: import("passport-google-oauth20").StrategyOptionsWithRequest]) => Strategy & {
|
|
4
10
|
validate(...args: any[]): unknown;
|
|
5
11
|
};
|
|
6
12
|
export declare class GoogleStrategy extends GoogleStrategy_base {
|
|
7
13
|
readonly _options: AuthenticationModuleOptions;
|
|
8
14
|
constructor(_options: AuthenticationModuleOptions);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
email: string | null;
|
|
13
|
-
firstName: string | null;
|
|
14
|
-
lastName: string | null;
|
|
15
|
-
avatar: string | null;
|
|
16
|
-
accessToken: string;
|
|
17
|
-
refreshToken: string;
|
|
18
|
-
}>;
|
|
15
|
+
fetchPhoneNumber(accessToken: string): Promise<string | null>;
|
|
16
|
+
fetchBirthday(accessToken: string): Promise<IBirthday | null>;
|
|
17
|
+
validate(accessToken: string, refreshToken: string, profile: Profile): Promise<any>;
|
|
19
18
|
}
|
|
20
19
|
export {};
|
|
@@ -16,6 +16,30 @@ let GoogleStrategy = class GoogleStrategy extends (0, passport_1.PassportStrateg
|
|
|
16
16
|
});
|
|
17
17
|
this._options = _options;
|
|
18
18
|
}
|
|
19
|
+
async fetchPhoneNumber(accessToken) {
|
|
20
|
+
const res = await fetch('https://people.googleapis.com/v1/people/me?personFields=phoneNumbers', {
|
|
21
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
22
|
+
});
|
|
23
|
+
const data = await res.json();
|
|
24
|
+
const phone = data.phoneNumbers?.[0]?.value ?? null;
|
|
25
|
+
return phone;
|
|
26
|
+
}
|
|
27
|
+
async fetchBirthday(accessToken) {
|
|
28
|
+
const r = await fetch('https://people.googleapis.com/v1/people/me?personFields=birthdays', { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
29
|
+
if (!r.ok)
|
|
30
|
+
return null;
|
|
31
|
+
const data = await r.json();
|
|
32
|
+
const list = data.birthdays ?? [];
|
|
33
|
+
// preferisci quello "primary", altrimenti il primo con date valorizzata
|
|
34
|
+
const entry = list.find((b) => b.metadata?.primary) ??
|
|
35
|
+
list.find((b) => b.date?.month && b.date?.day) ??
|
|
36
|
+
null;
|
|
37
|
+
if (!entry?.date)
|
|
38
|
+
return null;
|
|
39
|
+
const { year, month, day } = entry.date;
|
|
40
|
+
const date = new Date(year, month - 1, day, 12, 0, 0, 0);
|
|
41
|
+
return { year, month, day, date };
|
|
42
|
+
}
|
|
19
43
|
async validate(accessToken, refreshToken, profile) {
|
|
20
44
|
const { id, emails, name, photos } = profile;
|
|
21
45
|
const data = {
|
|
@@ -28,6 +52,14 @@ let GoogleStrategy = class GoogleStrategy extends (0, passport_1.PassportStrateg
|
|
|
28
52
|
accessToken,
|
|
29
53
|
refreshToken,
|
|
30
54
|
};
|
|
55
|
+
if (this._options.google.getBirthday) {
|
|
56
|
+
const bday = await this.fetchBirthday(accessToken);
|
|
57
|
+
data.birthday = bday;
|
|
58
|
+
}
|
|
59
|
+
if (this._options.google.getPhoneNumber) {
|
|
60
|
+
const phone = await this.fetchPhoneNumber(accessToken);
|
|
61
|
+
data.phone = phone;
|
|
62
|
+
}
|
|
31
63
|
return data;
|
|
32
64
|
}
|
|
33
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.google-oauth.strategy.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/google-oauth/auth.google-oauth.strategy.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,+CAAoD;AACpD,qEAA4D;AAC5D,uFAG6C;
|
|
1
|
+
{"version":3,"file":"auth.google-oauth.strategy.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/google-oauth/auth.google-oauth.strategy.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,+CAAoD;AACpD,qEAA4D;AAC5D,uFAG6C;AAUtC,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,IAAA,2BAAgB,EAAC,kCAAQ,EAAE,QAAQ,CAAC;IACtE,YAEW,QAAqC;QAE9C,KAAK,CAAC;YACJ,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;YAClC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY;YAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW;YACxC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK;SAC7B,CAAC,CAAC;QAPM,aAAQ,GAAR,QAAQ,CAA6B;IAQhD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,WAAmB;QACxC,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,sEAAsE,EACtE;YACE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CACF,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,MAAM,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