@akanjs/nest 0.0.54 → 0.0.56
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/index.mjs +1 -0
- package/package.json +7 -1
- package/src/authGuards.mjs +119 -0
- package/src/authentication.mjs +82 -0
- package/src/authorization.mjs +45 -0
- package/src/cacheClient.mjs +24 -0
- package/src/databaseClient.mjs +30 -0
- package/src/decorators.mjs +144 -0
- package/src/exceptions.mjs +57 -0
- package/src/exporter.mjs +76 -0
- package/src/generateSecrets.mjs +109 -0
- package/src/index.mjs +22 -0
- package/src/interceptors.mjs +169 -0
- package/src/mongoose.mjs +60 -0
- package/src/pipes.mjs +118 -0
- package/src/redis-io.adapter.mjs +61 -0
- package/src/searchClient.mjs +46 -0
- package/src/sso.mjs +155 -0
- package/src/verifyPayment.mjs +17 -0
package/src/sso.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { Injectable } from "@nestjs/common";
|
|
13
|
+
import { PassportStrategy } from "@nestjs/passport";
|
|
14
|
+
import * as appleSignin from "apple-signin";
|
|
15
|
+
import * as jwt from "jsonwebtoken";
|
|
16
|
+
import { Strategy as AppleStrategy } from "passport-apple";
|
|
17
|
+
import { Strategy as FacebookStrategy } from "passport-facebook";
|
|
18
|
+
import { Strategy as GithubStrategy } from "passport-github";
|
|
19
|
+
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
|
|
20
|
+
import { Strategy as KakaoStrategy } from "passport-kakao";
|
|
21
|
+
import { Strategy as NaverStrategy } from "passport-naver";
|
|
22
|
+
const getSsoProviders = (host, ssoOptions) => {
|
|
23
|
+
const origin = host === "localhost" ? "http://localhost:8080/backend" : `https://${host}/backend`;
|
|
24
|
+
const providers = [];
|
|
25
|
+
if (ssoOptions.kakao) {
|
|
26
|
+
let KakaoOauthStrategy = class extends PassportStrategy(KakaoStrategy, "kakao") {
|
|
27
|
+
constructor() {
|
|
28
|
+
super({
|
|
29
|
+
...ssoOptions.kakao,
|
|
30
|
+
callbackURL: `${origin}/user/kakao/callback`,
|
|
31
|
+
scope: ["account_email", "profile_nickname"]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
validate(jwt2, refreshToken, profile) {
|
|
35
|
+
return {
|
|
36
|
+
name: profile.displayName,
|
|
37
|
+
email: profile._json.kakao_account.email,
|
|
38
|
+
password: profile.id
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
KakaoOauthStrategy = __decorateClass([
|
|
43
|
+
Injectable()
|
|
44
|
+
], KakaoOauthStrategy);
|
|
45
|
+
providers.push(KakaoOauthStrategy);
|
|
46
|
+
}
|
|
47
|
+
if (ssoOptions.naver) {
|
|
48
|
+
let NaverOauthStrategy = class extends PassportStrategy(NaverStrategy, "naver") {
|
|
49
|
+
constructor() {
|
|
50
|
+
super({ ...ssoOptions.naver, callbackURL: `${origin}/user/naver/callback` });
|
|
51
|
+
}
|
|
52
|
+
validate(jwt2, refreshToken, profile) {
|
|
53
|
+
return {
|
|
54
|
+
name: profile.displayName,
|
|
55
|
+
email: profile._json.email,
|
|
56
|
+
password: profile.id
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
NaverOauthStrategy = __decorateClass([
|
|
61
|
+
Injectable()
|
|
62
|
+
], NaverOauthStrategy);
|
|
63
|
+
providers.push(NaverOauthStrategy);
|
|
64
|
+
}
|
|
65
|
+
if (ssoOptions.github) {
|
|
66
|
+
let GithubOauthStrategy = class extends PassportStrategy(GithubStrategy, "github") {
|
|
67
|
+
constructor() {
|
|
68
|
+
super({ ...ssoOptions.github, callbackURL: `${origin}/user/github/callback`, scope: ["user"] });
|
|
69
|
+
}
|
|
70
|
+
validate(accessToken, _refreshToken, profile) {
|
|
71
|
+
return profile;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
GithubOauthStrategy = __decorateClass([
|
|
75
|
+
Injectable()
|
|
76
|
+
], GithubOauthStrategy);
|
|
77
|
+
providers.push(GithubOauthStrategy);
|
|
78
|
+
}
|
|
79
|
+
if (ssoOptions.google) {
|
|
80
|
+
let GoogleOauthStrategy = class extends PassportStrategy(GoogleStrategy, "google") {
|
|
81
|
+
constructor() {
|
|
82
|
+
super({ ...ssoOptions.google, callbackURL: `${origin}/user/google/callback`, scope: ["email", "profile"] });
|
|
83
|
+
}
|
|
84
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
85
|
+
return profile;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
GoogleOauthStrategy = __decorateClass([
|
|
89
|
+
Injectable()
|
|
90
|
+
], GoogleOauthStrategy);
|
|
91
|
+
providers.push(GoogleOauthStrategy);
|
|
92
|
+
}
|
|
93
|
+
if (ssoOptions.facebook) {
|
|
94
|
+
let FacebookOauthStrategy = class extends PassportStrategy(FacebookStrategy, "facebook") {
|
|
95
|
+
constructor() {
|
|
96
|
+
super({
|
|
97
|
+
...ssoOptions.facebook,
|
|
98
|
+
callbackURL: `${origin}/user/facebook/callback`,
|
|
99
|
+
scope: ["email"],
|
|
100
|
+
profileFields: ["emails", "name"]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
104
|
+
return profile;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
FacebookOauthStrategy = __decorateClass([
|
|
108
|
+
Injectable()
|
|
109
|
+
], FacebookOauthStrategy);
|
|
110
|
+
providers.push(FacebookOauthStrategy);
|
|
111
|
+
}
|
|
112
|
+
if (ssoOptions.apple) {
|
|
113
|
+
let AppleOauthStrategy = class extends PassportStrategy(AppleStrategy, "apple") {
|
|
114
|
+
constructor() {
|
|
115
|
+
super({
|
|
116
|
+
...ssoOptions.apple,
|
|
117
|
+
callbackURL: `${origin}/user/apple/callback`,
|
|
118
|
+
passReqToCallback: true,
|
|
119
|
+
scope: ["name", "email"]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
validate(req, accessToken, refreshToken, idToken, profile, cb) {
|
|
123
|
+
cb(null, idToken);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
AppleOauthStrategy = __decorateClass([
|
|
127
|
+
Injectable()
|
|
128
|
+
], AppleOauthStrategy);
|
|
129
|
+
providers.push(AppleOauthStrategy);
|
|
130
|
+
}
|
|
131
|
+
return providers;
|
|
132
|
+
};
|
|
133
|
+
const verifyAppleUser = async (payload, origin, sso) => {
|
|
134
|
+
const signinAgent = appleSignin;
|
|
135
|
+
const clientSecret = signinAgent.getClientSecret({
|
|
136
|
+
clientID: sso.clientID,
|
|
137
|
+
teamId: sso.teamID,
|
|
138
|
+
keyIdentifier: sso.keyID,
|
|
139
|
+
privateKeyPath: sso.keyFilePath
|
|
140
|
+
});
|
|
141
|
+
const tokens = await signinAgent.getAuthorizationToken(payload.code, {
|
|
142
|
+
clientID: sso.clientID,
|
|
143
|
+
clientSecret,
|
|
144
|
+
redirectUri: `${origin}/user/apple/callback`
|
|
145
|
+
});
|
|
146
|
+
if (!tokens.id_token) {
|
|
147
|
+
throw new Error("No id_token found in Apple's response");
|
|
148
|
+
}
|
|
149
|
+
const data = jwt.decode(tokens.id_token);
|
|
150
|
+
return { tokens, data };
|
|
151
|
+
};
|
|
152
|
+
export {
|
|
153
|
+
getSsoProviders,
|
|
154
|
+
verifyAppleUser
|
|
155
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import iap from "iap";
|
|
2
|
+
const verifyPayment = async (payment) => {
|
|
3
|
+
return new Promise(
|
|
4
|
+
(resolve, reject) => (
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
6
|
+
iap.verifyPayment(payment.platform, { ...payment }, (error, response) => {
|
|
7
|
+
if (error)
|
|
8
|
+
reject(`App Purchase Verify Failed. ${response}`);
|
|
9
|
+
else
|
|
10
|
+
resolve(response);
|
|
11
|
+
})
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
verifyPayment
|
|
17
|
+
};
|