dn-react-router-toolkit 0.1.11 → 0.2.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/dist/auth/apple_auth.d.mts +38 -0
- package/dist/auth/apple_auth.d.ts +38 -0
- package/dist/{auth-kit → auth}/apple_auth.js +31 -18
- package/dist/auth/apple_auth.mjs +63 -0
- package/dist/{auth-kit/repository.d.mts → auth/auth_repository.d.mts} +6 -9
- package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +6 -9
- package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
- package/dist/{auth-kit → auth}/auth_service.d.mts +12 -22
- package/dist/{auth-kit → auth}/auth_service.d.ts +12 -22
- package/dist/{auth-kit → auth}/auth_service.js +30 -77
- package/dist/{auth-kit → auth}/auth_service.mjs +30 -77
- package/dist/auth/client/google_login_button.d.mts +7 -0
- package/dist/auth/client/google_login_button.d.ts +7 -0
- package/dist/{auth-kit → auth}/client/google_login_button.js +24 -19
- package/dist/auth/client/google_login_button.mjs +37 -0
- package/dist/auth/client/provider.d.mts +23 -0
- package/dist/auth/client/provider.d.ts +23 -0
- package/dist/auth/client/provider.js +137 -0
- package/dist/auth/client/provider.mjs +101 -0
- package/dist/{auth-kit → auth}/client/redirect_page.js +1 -1
- package/dist/{auth-kit → auth}/client/redirect_page.mjs +1 -1
- package/dist/auth/google_auth.d.mts +33 -0
- package/dist/auth/google_auth.d.ts +33 -0
- package/dist/{auth-kit → auth}/google_auth.js +23 -32
- package/dist/{auth-kit → auth}/google_auth.mjs +22 -31
- package/dist/auth/handlers/find_auth.d.mts +13 -0
- package/dist/auth/handlers/find_auth.d.ts +13 -0
- package/dist/{route/api/auth/route.js → auth/handlers/find_auth.js} +10 -10
- package/dist/{route/api/auth/route.mjs → auth/handlers/find_auth.mjs} +5 -5
- package/dist/auth/handlers/login.d.mts +13 -0
- package/dist/auth/handlers/login.d.ts +13 -0
- package/dist/{route/api/auth/login/route.js → auth/handlers/login.js} +17 -17
- package/dist/{route/api/auth/login/route.mjs → auth/handlers/login.mjs} +12 -12
- package/dist/auth/handlers/login_with_thirdparty.d.mts +15 -0
- package/dist/auth/handlers/login_with_thirdparty.d.ts +15 -0
- package/dist/{route/api/auth/login/[provider]/route.js → auth/handlers/login_with_thirdparty.js} +12 -27
- package/dist/{route/api/auth/login/[provider]/route.mjs → auth/handlers/login_with_thirdparty.mjs} +7 -22
- package/dist/auth/handlers/logout.d.mts +13 -0
- package/dist/auth/handlers/logout.d.ts +13 -0
- package/dist/{route/api/auth/logout/route.js → auth/handlers/logout.js} +15 -11
- package/dist/{route/api/auth/logout/route.mjs → auth/handlers/logout.mjs} +11 -7
- package/dist/auth/handlers/refresh.d.mts +13 -0
- package/dist/auth/handlers/refresh.d.ts +13 -0
- package/dist/{route/api/auth/refresh/route.js → auth/handlers/refresh.js} +12 -12
- package/dist/{route/api/auth/refresh/route.mjs → auth/handlers/refresh.mjs} +7 -7
- package/dist/auth/handlers/signup.d.mts +15 -0
- package/dist/auth/handlers/signup.d.ts +15 -0
- package/dist/auth/handlers/signup.js +135 -0
- package/dist/auth/handlers/signup.mjs +100 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
- package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
- package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
- package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
- package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
- package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
- package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
- package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
- package/dist/auth/kakao_auth.d.mts +27 -0
- package/dist/auth/kakao_auth.d.ts +27 -0
- package/dist/auth/kakao_auth.js +56 -0
- package/dist/auth/kakao_auth.mjs +31 -0
- package/dist/auth/thirdparty_auth.d.mts +41 -0
- package/dist/auth/thirdparty_auth.d.ts +41 -0
- package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
- package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
- package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
- package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
- package/dist/{auth-kit → auth}/with_auth.js +26 -42
- package/dist/auth/with_auth.mjs +63 -0
- package/dist/date.d.mts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +4 -2
- package/dist/date.mjs +2 -1
- package/dist/{file-kit → file}/cdn.js +1 -1
- package/dist/{file-kit → file}/cdn.mjs +1 -1
- package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
- package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
- package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
- package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
- package/dist/{file-kit → file}/client/file_uploader.js +3 -3
- package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
- package/dist/{file-kit → file}/client/format_size.js +1 -1
- package/dist/{file-kit → file}/client/format_size.mjs +1 -1
- package/dist/{file-kit → file}/client/metadata.js +1 -1
- package/dist/{file-kit → file}/client/metadata.mjs +1 -1
- package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
- package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
- package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
- package/dist/file/file_service.d.mts +32 -0
- package/dist/file/file_service.d.ts +32 -0
- package/dist/{file-kit → file}/file_service.js +27 -21
- package/dist/file/file_service.mjs +41 -0
- package/dist/file/handlers/delete_file.d.mts +17 -0
- package/dist/file/handlers/delete_file.d.ts +17 -0
- package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
- package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
- package/dist/file/handlers/upload_file.d.mts +16 -0
- package/dist/file/handlers/upload_file.d.ts +16 -0
- package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
- package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
- package/dist/{file-kit → file}/object_storage.d.mts +3 -1
- package/dist/{file-kit → file}/object_storage.d.ts +3 -1
- package/dist/{file-kit → file}/object_storage.js +2 -2
- package/dist/{file-kit → file}/object_storage.mjs +2 -2
- package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
- package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
- package/dist/{file-kit → file}/responsive_image.js +18 -9
- package/dist/{file-kit → file}/responsive_image.mjs +18 -9
- package/dist/{http-kit → http}/index.js +5 -5
- package/dist/{http-kit → http}/index.mjs +1 -1
- package/dist/{http-kit → http}/response.js +1 -1
- package/dist/{http-kit → http}/response.mjs +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/route/api.d.mts +15 -25
- package/dist/route/api.d.ts +15 -25
- package/dist/route/api.js +325 -178
- package/dist/route/api.mjs +314 -177
- package/dist/{seo-kit → seo}/seo.js +1 -1
- package/dist/{seo-kit → seo}/seo.mjs +1 -1
- package/package.json +74 -74
- package/dist/auth-kit/apple_auth.d.mts +0 -24
- package/dist/auth-kit/apple_auth.d.ts +0 -24
- package/dist/auth-kit/apple_auth.mjs +0 -50
- package/dist/auth-kit/client/google_login_button.d.mts +0 -9
- package/dist/auth-kit/client/google_login_button.d.ts +0 -9
- package/dist/auth-kit/client/google_login_button.mjs +0 -32
- package/dist/auth-kit/client/logout.d.mts +0 -3
- package/dist/auth-kit/client/logout.d.ts +0 -3
- package/dist/auth-kit/client/logout.js +0 -49
- package/dist/auth-kit/client/logout.mjs +0 -24
- package/dist/auth-kit/google_auth.d.mts +0 -27
- package/dist/auth-kit/google_auth.d.ts +0 -27
- package/dist/auth-kit/kakao_auth.d.mts +0 -24
- package/dist/auth-kit/kakao_auth.d.ts +0 -24
- package/dist/auth-kit/with_auth.mjs +0 -67
- package/dist/file-kit/file_service.d.mts +0 -26
- package/dist/file-kit/file_service.d.ts +0 -26
- package/dist/file-kit/file_service.mjs +0 -35
- package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
- package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
- package/dist/route/api/auth/login/route.d.mts +0 -14
- package/dist/route/api/auth/login/route.d.ts +0 -14
- package/dist/route/api/auth/logout/route.d.mts +0 -14
- package/dist/route/api/auth/logout/route.d.ts +0 -14
- package/dist/route/api/auth/refresh/route.d.mts +0 -13
- package/dist/route/api/auth/refresh/route.d.ts +0 -13
- package/dist/route/api/auth/route.d.mts +0 -13
- package/dist/route/api/auth/route.d.ts +0 -13
- package/dist/route/api/files/_fileId_/route.d.mts +0 -17
- package/dist/route/api/files/_fileId_/route.d.ts +0 -17
- package/dist/route/api/files/route.d.mts +0 -16
- package/dist/route/api/files/route.d.ts +0 -16
- package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
- package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
- /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
- /package/dist/{file-kit → file}/cdn.d.mts +0 -0
- /package/dist/{file-kit → file}/cdn.d.ts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
- /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
- /package/dist/{http-kit → http}/index.d.mts +0 -0
- /package/dist/{http-kit → http}/index.d.ts +0 -0
- /package/dist/{http-kit → http}/response.d.mts +0 -0
- /package/dist/{http-kit → http}/response.d.ts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
|
|
2
|
+
import './auth_service.mjs';
|
|
3
|
+
import 'jose';
|
|
4
|
+
import 'react-router';
|
|
5
|
+
import './jwt_manager.mjs';
|
|
6
|
+
import '../file/object_storage.mjs';
|
|
7
|
+
import '@aws-sdk/client-s3';
|
|
8
|
+
import './auth_repository.mjs';
|
|
9
|
+
|
|
10
|
+
declare class AppleAuth implements ThirdpartyAuth {
|
|
11
|
+
thirdpartyAuth: ThirdpartyAuthService;
|
|
12
|
+
appleAuthKey: string;
|
|
13
|
+
appleClientId: string;
|
|
14
|
+
appleTeamId: string;
|
|
15
|
+
appleKeyId: string;
|
|
16
|
+
appleServiceId: string;
|
|
17
|
+
constructor({ thirdpartyAuth, appleAuthKey, appleClientId, appleTeamId, appleKeyId, appleServiceId, }: {
|
|
18
|
+
thirdpartyAuth: ThirdpartyAuthService;
|
|
19
|
+
appleAuthKey: string;
|
|
20
|
+
appleClientId: string;
|
|
21
|
+
appleTeamId: string;
|
|
22
|
+
appleKeyId: string;
|
|
23
|
+
appleServiceId: string;
|
|
24
|
+
});
|
|
25
|
+
login(code: string, type?: "web" | "app"): Promise<{
|
|
26
|
+
user: {
|
|
27
|
+
id: string;
|
|
28
|
+
role: string;
|
|
29
|
+
name: string;
|
|
30
|
+
refreshToken: string | null;
|
|
31
|
+
};
|
|
32
|
+
accessToken: string;
|
|
33
|
+
refreshToken: string;
|
|
34
|
+
}>;
|
|
35
|
+
private generateAppleClientSecret;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { AppleAuth };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
|
|
2
|
+
import './auth_service.js';
|
|
3
|
+
import 'jose';
|
|
4
|
+
import 'react-router';
|
|
5
|
+
import './jwt_manager.js';
|
|
6
|
+
import '../file/object_storage.js';
|
|
7
|
+
import '@aws-sdk/client-s3';
|
|
8
|
+
import './auth_repository.js';
|
|
9
|
+
|
|
10
|
+
declare class AppleAuth implements ThirdpartyAuth {
|
|
11
|
+
thirdpartyAuth: ThirdpartyAuthService;
|
|
12
|
+
appleAuthKey: string;
|
|
13
|
+
appleClientId: string;
|
|
14
|
+
appleTeamId: string;
|
|
15
|
+
appleKeyId: string;
|
|
16
|
+
appleServiceId: string;
|
|
17
|
+
constructor({ thirdpartyAuth, appleAuthKey, appleClientId, appleTeamId, appleKeyId, appleServiceId, }: {
|
|
18
|
+
thirdpartyAuth: ThirdpartyAuthService;
|
|
19
|
+
appleAuthKey: string;
|
|
20
|
+
appleClientId: string;
|
|
21
|
+
appleTeamId: string;
|
|
22
|
+
appleKeyId: string;
|
|
23
|
+
appleServiceId: string;
|
|
24
|
+
});
|
|
25
|
+
login(code: string, type?: "web" | "app"): Promise<{
|
|
26
|
+
user: {
|
|
27
|
+
id: string;
|
|
28
|
+
role: string;
|
|
29
|
+
name: string;
|
|
30
|
+
refreshToken: string | null;
|
|
31
|
+
};
|
|
32
|
+
accessToken: string;
|
|
33
|
+
refreshToken: string;
|
|
34
|
+
}>;
|
|
35
|
+
private generateAppleClientSecret;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { AppleAuth };
|
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/auth
|
|
20
|
+
// src/auth/apple_auth.ts
|
|
21
21
|
var apple_auth_exports = {};
|
|
22
22
|
__export(apple_auth_exports, {
|
|
23
23
|
AppleAuth: () => AppleAuth
|
|
@@ -25,11 +25,28 @@ __export(apple_auth_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(apple_auth_exports);
|
|
26
26
|
var import_jose = require("jose");
|
|
27
27
|
var AppleAuth = class {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
thirdpartyAuth;
|
|
29
|
+
appleAuthKey;
|
|
30
|
+
appleClientId;
|
|
31
|
+
appleTeamId;
|
|
32
|
+
appleKeyId;
|
|
33
|
+
appleServiceId;
|
|
34
|
+
constructor({
|
|
35
|
+
thirdpartyAuth,
|
|
36
|
+
appleAuthKey,
|
|
37
|
+
appleClientId,
|
|
38
|
+
appleTeamId,
|
|
39
|
+
appleKeyId,
|
|
40
|
+
appleServiceId
|
|
41
|
+
}) {
|
|
42
|
+
this.thirdpartyAuth = thirdpartyAuth;
|
|
43
|
+
this.appleAuthKey = appleAuthKey;
|
|
44
|
+
this.appleClientId = appleClientId;
|
|
45
|
+
this.appleTeamId = appleTeamId;
|
|
46
|
+
this.appleKeyId = appleKeyId;
|
|
47
|
+
this.appleServiceId = appleServiceId;
|
|
31
48
|
}
|
|
32
|
-
async
|
|
49
|
+
async login(code, type = "web") {
|
|
33
50
|
const url = "https://appleid.apple.com/auth/token";
|
|
34
51
|
const client_secret = await this.generateAppleClientSecret(type);
|
|
35
52
|
const res = await fetch(url, {
|
|
@@ -38,7 +55,7 @@ var AppleAuth = class {
|
|
|
38
55
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
39
56
|
},
|
|
40
57
|
body: new URLSearchParams({
|
|
41
|
-
client_id: type === "web" ?
|
|
58
|
+
client_id: type === "web" ? this.appleServiceId : this.appleClientId,
|
|
42
59
|
client_secret,
|
|
43
60
|
code,
|
|
44
61
|
grant_type: "authorization_code"
|
|
@@ -50,23 +67,19 @@ var AppleAuth = class {
|
|
|
50
67
|
}
|
|
51
68
|
const data = await res.json();
|
|
52
69
|
const { id_token } = data;
|
|
53
|
-
const
|
|
54
|
-
const { sub, email, name } =
|
|
55
|
-
const
|
|
70
|
+
const appleAuth = (0, import_jose.decodeJwt)(id_token);
|
|
71
|
+
const { sub, email, name } = appleAuth;
|
|
72
|
+
const payload = {
|
|
56
73
|
id: sub,
|
|
57
74
|
email,
|
|
58
75
|
name
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { user, accessToken, refreshToken };
|
|
76
|
+
};
|
|
77
|
+
return this.thirdpartyAuth.issueTokensIfUserFound("apple", payload);
|
|
62
78
|
}
|
|
63
79
|
async generateAppleClientSecret(type = "web") {
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const clientId = type === "web" ? process.env.APPLE_SERVICE_ID : process.env.APPLE_CLIENT_ID;
|
|
68
|
-
const keyObject = await (0, import_jose.importPKCS8)(authKey, "ES256");
|
|
69
|
-
return new import_jose.SignJWT().setProtectedHeader({ alg: "ES256", kid: keyId }).setIssuedAt().setIssuer(teamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
|
|
80
|
+
const clientId = type === "web" ? this.appleServiceId : this.appleClientId;
|
|
81
|
+
const keyObject = await (0, import_jose.importPKCS8)(this.appleAuthKey, "ES256");
|
|
82
|
+
return new import_jose.SignJWT().setProtectedHeader({ alg: "ES256", kid: this.appleKeyId }).setIssuedAt().setIssuer(this.appleTeamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
|
|
70
83
|
}
|
|
71
84
|
};
|
|
72
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/auth/apple_auth.ts
|
|
2
|
+
import { decodeJwt, importPKCS8, SignJWT } from "jose";
|
|
3
|
+
var AppleAuth = class {
|
|
4
|
+
thirdpartyAuth;
|
|
5
|
+
appleAuthKey;
|
|
6
|
+
appleClientId;
|
|
7
|
+
appleTeamId;
|
|
8
|
+
appleKeyId;
|
|
9
|
+
appleServiceId;
|
|
10
|
+
constructor({
|
|
11
|
+
thirdpartyAuth,
|
|
12
|
+
appleAuthKey,
|
|
13
|
+
appleClientId,
|
|
14
|
+
appleTeamId,
|
|
15
|
+
appleKeyId,
|
|
16
|
+
appleServiceId
|
|
17
|
+
}) {
|
|
18
|
+
this.thirdpartyAuth = thirdpartyAuth;
|
|
19
|
+
this.appleAuthKey = appleAuthKey;
|
|
20
|
+
this.appleClientId = appleClientId;
|
|
21
|
+
this.appleTeamId = appleTeamId;
|
|
22
|
+
this.appleKeyId = appleKeyId;
|
|
23
|
+
this.appleServiceId = appleServiceId;
|
|
24
|
+
}
|
|
25
|
+
async login(code, type = "web") {
|
|
26
|
+
const url = "https://appleid.apple.com/auth/token";
|
|
27
|
+
const client_secret = await this.generateAppleClientSecret(type);
|
|
28
|
+
const res = await fetch(url, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
32
|
+
},
|
|
33
|
+
body: new URLSearchParams({
|
|
34
|
+
client_id: type === "web" ? this.appleServiceId : this.appleClientId,
|
|
35
|
+
client_secret,
|
|
36
|
+
code,
|
|
37
|
+
grant_type: "authorization_code"
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
console.error(await res.text());
|
|
42
|
+
throw new Error("Apple \uC778\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
|
|
43
|
+
}
|
|
44
|
+
const data = await res.json();
|
|
45
|
+
const { id_token } = data;
|
|
46
|
+
const appleAuth = decodeJwt(id_token);
|
|
47
|
+
const { sub, email, name } = appleAuth;
|
|
48
|
+
const payload = {
|
|
49
|
+
id: sub,
|
|
50
|
+
email,
|
|
51
|
+
name
|
|
52
|
+
};
|
|
53
|
+
return this.thirdpartyAuth.issueTokensIfUserFound("apple", payload);
|
|
54
|
+
}
|
|
55
|
+
async generateAppleClientSecret(type = "web") {
|
|
56
|
+
const clientId = type === "web" ? this.appleServiceId : this.appleClientId;
|
|
57
|
+
const keyObject = await importPKCS8(this.appleAuthKey, "ES256");
|
|
58
|
+
return new SignJWT().setProtectedHeader({ alg: "ES256", kid: this.appleKeyId }).setIssuedAt().setIssuer(this.appleTeamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
AppleAuth
|
|
63
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface AuthRepository {
|
|
1
|
+
interface AuthRepository<TFile = unknown> {
|
|
2
2
|
findCredentialById(id: string): Promise<{
|
|
3
3
|
password: string;
|
|
4
4
|
userId: string;
|
|
@@ -13,9 +13,9 @@ interface AuthRepository {
|
|
|
13
13
|
createUser(userData: {
|
|
14
14
|
id: string;
|
|
15
15
|
role: string;
|
|
16
|
-
profileImageId: string | null;
|
|
17
16
|
name: string;
|
|
18
17
|
email: string;
|
|
18
|
+
profileImage?: TFile;
|
|
19
19
|
}): Promise<{
|
|
20
20
|
id: string;
|
|
21
21
|
role: string;
|
|
@@ -24,18 +24,15 @@ interface AuthRepository {
|
|
|
24
24
|
findThirdPartyAuth(provider: string, providerId: string): Promise<{
|
|
25
25
|
userId: string;
|
|
26
26
|
} | undefined>;
|
|
27
|
-
createThirdPartyAuth(
|
|
27
|
+
createThirdPartyAuth(params: {
|
|
28
28
|
id: string;
|
|
29
29
|
provider: string;
|
|
30
30
|
userId: string;
|
|
31
31
|
}): Promise<void>;
|
|
32
|
-
|
|
32
|
+
createCredential(params: {
|
|
33
33
|
id: string;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
key: string;
|
|
37
|
-
size: number;
|
|
38
|
-
metadata: Record<string, any>;
|
|
34
|
+
password: string;
|
|
35
|
+
userId: string;
|
|
39
36
|
}): Promise<void>;
|
|
40
37
|
}
|
|
41
38
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface AuthRepository {
|
|
1
|
+
interface AuthRepository<TFile = unknown> {
|
|
2
2
|
findCredentialById(id: string): Promise<{
|
|
3
3
|
password: string;
|
|
4
4
|
userId: string;
|
|
@@ -13,9 +13,9 @@ interface AuthRepository {
|
|
|
13
13
|
createUser(userData: {
|
|
14
14
|
id: string;
|
|
15
15
|
role: string;
|
|
16
|
-
profileImageId: string | null;
|
|
17
16
|
name: string;
|
|
18
17
|
email: string;
|
|
18
|
+
profileImage?: TFile;
|
|
19
19
|
}): Promise<{
|
|
20
20
|
id: string;
|
|
21
21
|
role: string;
|
|
@@ -24,18 +24,15 @@ interface AuthRepository {
|
|
|
24
24
|
findThirdPartyAuth(provider: string, providerId: string): Promise<{
|
|
25
25
|
userId: string;
|
|
26
26
|
} | undefined>;
|
|
27
|
-
createThirdPartyAuth(
|
|
27
|
+
createThirdPartyAuth(params: {
|
|
28
28
|
id: string;
|
|
29
29
|
provider: string;
|
|
30
30
|
userId: string;
|
|
31
31
|
}): Promise<void>;
|
|
32
|
-
|
|
32
|
+
createCredential(params: {
|
|
33
33
|
id: string;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
key: string;
|
|
37
|
-
size: number;
|
|
38
|
-
metadata: Record<string, any>;
|
|
34
|
+
password: string;
|
|
35
|
+
userId: string;
|
|
39
36
|
}): Promise<void>;
|
|
40
37
|
}
|
|
41
38
|
|
|
@@ -13,6 +13,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
15
|
|
|
16
|
-
// src/
|
|
17
|
-
var
|
|
18
|
-
module.exports = __toCommonJS(
|
|
16
|
+
// src/auth/auth_repository.ts
|
|
17
|
+
var auth_repository_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(auth_repository_exports);
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import * as jose from 'jose';
|
|
2
2
|
import * as react_router from 'react-router';
|
|
3
|
-
import { JWTManager } from './
|
|
4
|
-
import { ObjectStorage } from '../file
|
|
5
|
-
import { AuthRepository } from './
|
|
3
|
+
import { JWTManager } from './jwt_manager.mjs';
|
|
4
|
+
import { ObjectStorage } from '../file/object_storage.mjs';
|
|
5
|
+
import { AuthRepository } from './auth_repository.mjs';
|
|
6
6
|
import '@aws-sdk/client-s3';
|
|
7
7
|
|
|
8
8
|
declare const ACCESS_TOKEN_KEY = "access_token";
|
|
9
9
|
declare const REFRESH_TOKEN_KEY = "refresh_token";
|
|
10
10
|
declare const ACCESS_TOKEN_COOKIE: react_router.Cookie;
|
|
11
11
|
declare const REFRESH_TOKEN_COOKIE: react_router.Cookie;
|
|
12
|
-
declare class AuthService {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
declare class AuthService<TFile = unknown> {
|
|
13
|
+
authRepository: AuthRepository<TFile>;
|
|
14
|
+
jwtManager: JWTManager;
|
|
15
|
+
objectStorage: ObjectStorage;
|
|
16
|
+
constructor({ authRepository, jwtManager, objectStorage, }: {
|
|
17
|
+
authRepository: AuthRepository<TFile>;
|
|
18
|
+
jwtManager: JWTManager;
|
|
19
|
+
objectStorage: ObjectStorage;
|
|
20
20
|
});
|
|
21
21
|
verify(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
22
22
|
verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
23
|
+
getAccessTokenFromRequest(request: Request): Promise<any>;
|
|
23
24
|
getAccessTokenFromCookies(request: Request): Promise<any>;
|
|
24
25
|
getRefreshTokenFromCookies(request: Request): Promise<any>;
|
|
25
26
|
refresh(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
@@ -57,17 +58,6 @@ declare class AuthService {
|
|
|
57
58
|
name: string;
|
|
58
59
|
refreshToken: string | null;
|
|
59
60
|
} | undefined>;
|
|
60
|
-
getOrCreateUser(provider: string, info: {
|
|
61
|
-
id: string;
|
|
62
|
-
email: string;
|
|
63
|
-
name?: string;
|
|
64
|
-
picture?: string;
|
|
65
|
-
}): Promise<{
|
|
66
|
-
id: string;
|
|
67
|
-
role: string;
|
|
68
|
-
name: string;
|
|
69
|
-
}>;
|
|
70
|
-
protected savePicture(picture?: string): Promise<string | undefined>;
|
|
71
61
|
}
|
|
72
62
|
|
|
73
63
|
export { ACCESS_TOKEN_COOKIE, ACCESS_TOKEN_KEY, AuthService, REFRESH_TOKEN_COOKIE, REFRESH_TOKEN_KEY };
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import * as jose from 'jose';
|
|
2
2
|
import * as react_router from 'react-router';
|
|
3
|
-
import { JWTManager } from './
|
|
4
|
-
import { ObjectStorage } from '../file
|
|
5
|
-
import { AuthRepository } from './
|
|
3
|
+
import { JWTManager } from './jwt_manager.js';
|
|
4
|
+
import { ObjectStorage } from '../file/object_storage.js';
|
|
5
|
+
import { AuthRepository } from './auth_repository.js';
|
|
6
6
|
import '@aws-sdk/client-s3';
|
|
7
7
|
|
|
8
8
|
declare const ACCESS_TOKEN_KEY = "access_token";
|
|
9
9
|
declare const REFRESH_TOKEN_KEY = "refresh_token";
|
|
10
10
|
declare const ACCESS_TOKEN_COOKIE: react_router.Cookie;
|
|
11
11
|
declare const REFRESH_TOKEN_COOKIE: react_router.Cookie;
|
|
12
|
-
declare class AuthService {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
declare class AuthService<TFile = unknown> {
|
|
13
|
+
authRepository: AuthRepository<TFile>;
|
|
14
|
+
jwtManager: JWTManager;
|
|
15
|
+
objectStorage: ObjectStorage;
|
|
16
|
+
constructor({ authRepository, jwtManager, objectStorage, }: {
|
|
17
|
+
authRepository: AuthRepository<TFile>;
|
|
18
|
+
jwtManager: JWTManager;
|
|
19
|
+
objectStorage: ObjectStorage;
|
|
20
20
|
});
|
|
21
21
|
verify(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
22
22
|
verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
23
|
+
getAccessTokenFromRequest(request: Request): Promise<any>;
|
|
23
24
|
getAccessTokenFromCookies(request: Request): Promise<any>;
|
|
24
25
|
getRefreshTokenFromCookies(request: Request): Promise<any>;
|
|
25
26
|
refresh(request: Request): Promise<jose.JWTPayload | undefined>;
|
|
@@ -57,17 +58,6 @@ declare class AuthService {
|
|
|
57
58
|
name: string;
|
|
58
59
|
refreshToken: string | null;
|
|
59
60
|
} | undefined>;
|
|
60
|
-
getOrCreateUser(provider: string, info: {
|
|
61
|
-
id: string;
|
|
62
|
-
email: string;
|
|
63
|
-
name?: string;
|
|
64
|
-
picture?: string;
|
|
65
|
-
}): Promise<{
|
|
66
|
-
id: string;
|
|
67
|
-
role: string;
|
|
68
|
-
name: string;
|
|
69
|
-
}>;
|
|
70
|
-
protected savePicture(picture?: string): Promise<string | undefined>;
|
|
71
61
|
}
|
|
72
62
|
|
|
73
63
|
export { ACCESS_TOKEN_COOKIE, ACCESS_TOKEN_KEY, AuthService, REFRESH_TOKEN_COOKIE, REFRESH_TOKEN_KEY };
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/auth
|
|
30
|
+
// src/auth/auth_service.ts
|
|
31
31
|
var auth_service_exports = {};
|
|
32
32
|
__export(auth_service_exports, {
|
|
33
33
|
ACCESS_TOKEN_COOKIE: () => ACCESS_TOKEN_COOKIE,
|
|
@@ -38,7 +38,6 @@ __export(auth_service_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(auth_service_exports);
|
|
40
40
|
var import_bcryptjs = __toESM(require("bcryptjs"));
|
|
41
|
-
var import_uuid = require("uuid");
|
|
42
41
|
var import_react_router = require("react-router");
|
|
43
42
|
var ACCESS_TOKEN_KEY = "access_token";
|
|
44
43
|
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
@@ -55,22 +54,22 @@ var REFRESH_TOKEN_COOKIE = (0, import_react_router.createCookie)(REFRESH_TOKEN_K
|
|
|
55
54
|
sameSite: "strict"
|
|
56
55
|
});
|
|
57
56
|
var AuthService = class {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
authRepository;
|
|
58
|
+
jwtManager;
|
|
59
|
+
objectStorage;
|
|
61
60
|
constructor({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
authRepository,
|
|
62
|
+
jwtManager,
|
|
63
|
+
objectStorage
|
|
65
64
|
}) {
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
65
|
+
this.authRepository = authRepository;
|
|
66
|
+
this.jwtManager = jwtManager;
|
|
67
|
+
this.objectStorage = objectStorage;
|
|
69
68
|
}
|
|
70
69
|
async verify(request) {
|
|
71
|
-
const accessToken =
|
|
70
|
+
const accessToken = await this.getAccessTokenFromRequest(request);
|
|
72
71
|
if (accessToken) {
|
|
73
|
-
return this.
|
|
72
|
+
return this.jwtManager.verifyAccessToken(accessToken);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
async verifyOrRefresh(request) {
|
|
@@ -80,6 +79,12 @@ var AuthService = class {
|
|
|
80
79
|
}
|
|
81
80
|
return this.refresh(request);
|
|
82
81
|
}
|
|
82
|
+
async getAccessTokenFromRequest(request) {
|
|
83
|
+
if (request.headers.get("Authorization")) {
|
|
84
|
+
return request.headers.get("Authorization")?.replace("Bearer ", "");
|
|
85
|
+
}
|
|
86
|
+
return this.getAccessTokenFromCookies(request);
|
|
87
|
+
}
|
|
83
88
|
async getAccessTokenFromCookies(request) {
|
|
84
89
|
const accessToken = await ACCESS_TOKEN_COOKIE.parse(
|
|
85
90
|
request.headers.get("cookie")
|
|
@@ -100,7 +105,7 @@ var AuthService = class {
|
|
|
100
105
|
refreshToken
|
|
101
106
|
);
|
|
102
107
|
await this.getAccessTokenSetCookie(refreshedAccessToken);
|
|
103
|
-
const payload = this.
|
|
108
|
+
const payload = this.jwtManager.decode(refreshedAccessToken);
|
|
104
109
|
if (payload) {
|
|
105
110
|
return payload;
|
|
106
111
|
}
|
|
@@ -113,14 +118,14 @@ var AuthService = class {
|
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
async signIn({ id, password }) {
|
|
116
|
-
const credential = await this.
|
|
121
|
+
const credential = await this.authRepository.findCredentialById(id);
|
|
117
122
|
if (!credential) {
|
|
118
123
|
throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
|
|
119
124
|
}
|
|
120
125
|
if (!await import_bcryptjs.default.compare(password, credential.password)) {
|
|
121
126
|
throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
|
|
122
127
|
}
|
|
123
|
-
const user = await this.
|
|
128
|
+
const user = await this.authRepository.findUserById(credential.userId);
|
|
124
129
|
if (!user) {
|
|
125
130
|
throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
126
131
|
}
|
|
@@ -131,19 +136,19 @@ var AuthService = class {
|
|
|
131
136
|
};
|
|
132
137
|
}
|
|
133
138
|
async issueAccessToken(user) {
|
|
134
|
-
return this.
|
|
139
|
+
return this.jwtManager.signAccessToken({
|
|
135
140
|
userId: user.id,
|
|
136
141
|
role: user.role,
|
|
137
142
|
name: user.name
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
145
|
async issueTokenPair(user) {
|
|
141
|
-
const refreshToken = await this.
|
|
146
|
+
const refreshToken = await this.jwtManager.signRefreshToken({
|
|
142
147
|
userId: user.id,
|
|
143
148
|
role: user.role,
|
|
144
149
|
name: user.name
|
|
145
150
|
});
|
|
146
|
-
await this.
|
|
151
|
+
await this.authRepository.updateUserRefreshToken(
|
|
147
152
|
user.id,
|
|
148
153
|
await import_bcryptjs.default.hash(refreshToken, 10)
|
|
149
154
|
);
|
|
@@ -151,7 +156,7 @@ var AuthService = class {
|
|
|
151
156
|
return { refreshToken, accessToken };
|
|
152
157
|
}
|
|
153
158
|
async refreshAccessToken(refreshToken) {
|
|
154
|
-
const payload = await this.
|
|
159
|
+
const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
|
|
155
160
|
if (!payload) {
|
|
156
161
|
throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
157
162
|
}
|
|
@@ -159,7 +164,7 @@ var AuthService = class {
|
|
|
159
164
|
if (typeof userId !== "string") {
|
|
160
165
|
throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
|
|
161
166
|
}
|
|
162
|
-
const user = await this.
|
|
167
|
+
const user = await this.authRepository.findUserById(userId);
|
|
163
168
|
if (!user) {
|
|
164
169
|
throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
|
|
165
170
|
}
|
|
@@ -174,77 +179,25 @@ var AuthService = class {
|
|
|
174
179
|
}
|
|
175
180
|
async getAccessTokenSetCookie(accessToken) {
|
|
176
181
|
return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
|
|
177
|
-
expires: accessToken ? this.
|
|
182
|
+
expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
|
|
178
183
|
});
|
|
179
184
|
}
|
|
180
185
|
async getRefreshTokenSetCookie(refreshToken) {
|
|
181
186
|
return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
|
|
182
|
-
expires: refreshToken ? this.
|
|
187
|
+
expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
|
|
183
188
|
});
|
|
184
189
|
}
|
|
185
190
|
async findUser(provider, info) {
|
|
186
|
-
const thirdPartyAuth = await this.
|
|
187
|
-
provider,
|
|
188
|
-
info.id
|
|
189
|
-
);
|
|
190
|
-
if (thirdPartyAuth) {
|
|
191
|
-
const user = await this.repository.findUserById(thirdPartyAuth.userId);
|
|
192
|
-
if (user) {
|
|
193
|
-
return user;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async getOrCreateUser(provider, info) {
|
|
198
|
-
const thirdPartyAuth = await this.repository.findThirdPartyAuth(
|
|
191
|
+
const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
|
|
199
192
|
provider,
|
|
200
193
|
info.id
|
|
201
194
|
);
|
|
202
195
|
if (thirdPartyAuth) {
|
|
203
|
-
const user = await this.
|
|
196
|
+
const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
|
|
204
197
|
if (user) {
|
|
205
198
|
return user;
|
|
206
199
|
}
|
|
207
200
|
}
|
|
208
|
-
const userId = (0, import_uuid.v4)();
|
|
209
|
-
const email = info.email;
|
|
210
|
-
const name = info.name || "\uC775\uBA85";
|
|
211
|
-
const picture = info.picture;
|
|
212
|
-
const profileImageId = await this.savePicture(picture) || null;
|
|
213
|
-
const result = await this.repository.createUser({
|
|
214
|
-
id: userId,
|
|
215
|
-
role: "user",
|
|
216
|
-
profileImageId,
|
|
217
|
-
name,
|
|
218
|
-
email
|
|
219
|
-
});
|
|
220
|
-
await this.repository.createThirdPartyAuth({
|
|
221
|
-
id: info.id,
|
|
222
|
-
provider,
|
|
223
|
-
userId
|
|
224
|
-
});
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
async savePicture(picture) {
|
|
228
|
-
if (!picture) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const res = await fetch(picture);
|
|
232
|
-
if (!res.ok) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
const buffer = await res.arrayBuffer();
|
|
236
|
-
const id = (0, import_uuid.v4)();
|
|
237
|
-
const key = `/users/${id}/picture`;
|
|
238
|
-
await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
|
|
239
|
-
await this.repository.createFile({
|
|
240
|
-
id,
|
|
241
|
-
name: "picture",
|
|
242
|
-
type: "image/*",
|
|
243
|
-
key,
|
|
244
|
-
size: buffer.byteLength,
|
|
245
|
-
metadata: {}
|
|
246
|
-
});
|
|
247
|
-
return id;
|
|
248
201
|
}
|
|
249
202
|
};
|
|
250
203
|
// Annotate the CommonJS export names for ESM import in node:
|