@ytsaurus/ui 1.12.2 → 1.13.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/build/cjs/@types/core.d.ts +38 -0
- package/build/cjs/server/components/layout-config.js +6 -1
- package/build/cjs/server/components/layout-config.js.map +1 -1
- package/build/cjs/server/components/oauth.d.ts +26 -0
- package/build/cjs/server/components/oauth.js +123 -0
- package/build/cjs/server/components/oauth.js.map +1 -0
- package/build/cjs/server/components/yt-auth.d.ts +6 -0
- package/build/cjs/server/components/yt-auth.js +23 -0
- package/build/cjs/server/components/yt-auth.js.map +1 -0
- package/build/cjs/server/controllers/login.d.ts +0 -1
- package/build/cjs/server/controllers/login.js +4 -26
- package/build/cjs/server/controllers/login.js.map +1 -1
- package/build/cjs/server/controllers/logout.d.ts +2 -0
- package/build/cjs/server/controllers/logout.js +15 -0
- package/build/cjs/server/controllers/logout.js.map +1 -0
- package/build/cjs/server/controllers/oauth-login.d.ts +4 -0
- package/build/cjs/server/controllers/oauth-login.js +30 -0
- package/build/cjs/server/controllers/oauth-login.js.map +1 -0
- package/build/cjs/server/index.js +9 -1
- package/build/cjs/server/index.js.map +1 -1
- package/build/cjs/server/middlewares/authorization.d.ts +2 -0
- package/build/cjs/server/middlewares/authorization.js +42 -0
- package/build/cjs/server/middlewares/authorization.js.map +1 -0
- package/build/cjs/server/middlewares/oauth.d.ts +2 -0
- package/build/cjs/server/middlewares/oauth.js +27 -0
- package/build/cjs/server/middlewares/oauth.js.map +1 -0
- package/build/cjs/server/middlewares/yt-auth.d.ts +1 -1
- package/build/cjs/server/middlewares/yt-auth.js +10 -42
- package/build/cjs/server/middlewares/yt-auth.js.map +1 -1
- package/build/cjs/server/routes.js +6 -1
- package/build/cjs/server/routes.js.map +1 -1
- package/build/cjs/server/utils/authorization.d.ts +6 -0
- package/build/cjs/server/utils/authorization.js +33 -0
- package/build/cjs/server/utils/authorization.js.map +1 -0
- package/build/cjs/shared/constants/index.d.ts +3 -0
- package/build/cjs/shared/constants/index.js +3 -1
- package/build/cjs/shared/constants/index.js.map +1 -1
- package/build/cjs/shared/yt-types.d.ts +2 -0
- package/build/cjs/ui/components/Login/LoginFormPage/LoginFormPage.js +23 -5
- package/build/cjs/ui/components/Login/LoginFormPage/LoginFormPage.js.map +1 -1
- package/build/cjs/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css +8 -0
- package/build/cjs/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css.map +1 -1
- package/build/cjs/ui/components/NumberInput/NumberInput.d.ts +1 -1
- package/build/cjs/ui/containers/AppNavigation/AppNavigation.js +2 -0
- package/build/cjs/ui/containers/AppNavigation/AppNavigation.js.map +1 -1
- package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.d.ts +1 -1
- package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.js +5 -7
- package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.js.map +1 -1
- package/build/cjs/ui/containers/AppNavigation/AppNavigationPageLayout.d.ts +2 -0
- package/build/cjs/ui/containers/AppNavigation/AppNavigationPageLayout.js.map +1 -1
- package/build/cjs/ui/store/reducers/global/index.d.ts +1 -0
- package/build/cjs/ui/store/reducers/global/index.js +1 -0
- package/build/cjs/ui/store/reducers/global/index.js.map +1 -1
- package/build/cjs/ui/store/selectors/global/index.d.ts +4 -0
- package/build/cjs/ui/store/selectors/global/index.js +14 -4
- package/build/cjs/ui/store/selectors/global/index.js.map +1 -1
- package/build/esm/@types/core.d.ts +38 -0
- package/build/esm/server/components/layout-config.js +7 -2
- package/build/esm/server/components/layout-config.js.map +1 -1
- package/build/esm/server/components/oauth.d.ts +26 -0
- package/build/esm/server/components/oauth.js +169 -0
- package/build/esm/server/components/oauth.js.map +1 -0
- package/build/esm/server/components/yt-auth.d.ts +6 -0
- package/build/esm/server/components/yt-auth.js +17 -0
- package/build/esm/server/components/yt-auth.js.map +1 -0
- package/build/esm/server/controllers/login.d.ts +0 -1
- package/build/esm/server/controllers/login.js +41 -88
- package/build/esm/server/controllers/login.js.map +1 -1
- package/build/esm/server/controllers/logout.d.ts +2 -0
- package/build/esm/server/controllers/logout.js +11 -0
- package/build/esm/server/controllers/logout.js.map +1 -0
- package/build/esm/server/controllers/oauth-login.d.ts +4 -0
- package/build/esm/server/controllers/oauth-login.js +50 -0
- package/build/esm/server/controllers/oauth-login.js.map +1 -0
- package/build/esm/server/index.js +7 -2
- package/build/esm/server/index.js.map +1 -1
- package/build/esm/server/middlewares/authorization.d.ts +2 -0
- package/build/esm/server/middlewares/authorization.js +74 -0
- package/build/esm/server/middlewares/authorization.js.map +1 -0
- package/build/esm/server/middlewares/oauth.d.ts +2 -0
- package/build/esm/server/middlewares/oauth.js +50 -0
- package/build/esm/server/middlewares/oauth.js.map +1 -0
- package/build/esm/server/middlewares/yt-auth.d.ts +1 -1
- package/build/esm/server/middlewares/yt-auth.js +8 -58
- package/build/esm/server/middlewares/yt-auth.js.map +1 -1
- package/build/esm/server/routes.js +16 -2
- package/build/esm/server/routes.js.map +1 -1
- package/build/esm/server/utils/authorization.d.ts +6 -0
- package/build/esm/server/utils/authorization.js +28 -0
- package/build/esm/server/utils/authorization.js.map +1 -0
- package/build/esm/shared/constants/index.d.ts +3 -0
- package/build/esm/shared/constants/index.js +2 -1
- package/build/esm/shared/constants/index.js.map +1 -1
- package/build/esm/shared/yt-types.d.ts +2 -0
- package/build/esm/ui/components/Login/LoginFormPage/LoginFormPage.js +24 -6
- package/build/esm/ui/components/Login/LoginFormPage/LoginFormPage.js.map +1 -1
- package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css +8 -0
- package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css.map +1 -1
- package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.scss +12 -0
- package/build/esm/ui/components/NumberInput/NumberInput.d.ts +1 -1
- package/build/esm/ui/containers/AppNavigation/AppNavigation.js +3 -1
- package/build/esm/ui/containers/AppNavigation/AppNavigation.js.map +1 -1
- package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.d.ts +1 -1
- package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.js +5 -7
- package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.js.map +1 -1
- package/build/esm/ui/containers/AppNavigation/AppNavigationPageLayout.d.ts +2 -0
- package/build/esm/ui/containers/AppNavigation/AppNavigationPageLayout.js.map +1 -1
- package/build/esm/ui/store/reducers/global/index.d.ts +1 -0
- package/build/esm/ui/store/reducers/global/index.js +1 -0
- package/build/esm/ui/store/reducers/global/index.js.map +1 -1
- package/build/esm/ui/store/selectors/global/index.d.ts +4 -0
- package/build/esm/ui/store/selectors/global/index.js +12 -2
- package/build/esm/ui/store/selectors/global/index.js.map +1 -1
- package/dist/public/build/assets-manifest.json +12 -12
- package/dist/public/build/css/{main.136a49c7.css → main.e919e247.css} +2 -2
- package/dist/public/build/css/main.e919e247.css.map +1 -0
- package/dist/public/build/js/89.07445d46.chunk.js +2 -0
- package/dist/public/build/js/89.07445d46.chunk.js.map +1 -0
- package/dist/public/build/js/main.9d592639.js +3 -0
- package/dist/public/build/js/{main.f91e3651.js.map → main.9d592639.js.map} +1 -1
- package/dist/public/build/js/{runtime.6c8d85d3.js → runtime.9491563b.js} +2 -2
- package/dist/public/build/js/{runtime.6c8d85d3.js.map → runtime.9491563b.js.map} +1 -1
- package/dist/public/build/manifest.json +8 -8
- package/dist/server/components/layout-config.js +6 -1
- package/dist/server/components/oauth.d.ts +26 -0
- package/dist/server/components/oauth.js +123 -0
- package/dist/server/components/yt-auth.d.ts +6 -0
- package/dist/server/components/yt-auth.js +23 -0
- package/dist/server/controllers/login.d.ts +0 -1
- package/dist/server/controllers/login.js +4 -26
- package/dist/server/controllers/logout.d.ts +2 -0
- package/dist/server/controllers/logout.js +15 -0
- package/dist/server/controllers/oauth-login.d.ts +4 -0
- package/dist/server/controllers/oauth-login.js +30 -0
- package/dist/server/index.js +9 -1
- package/dist/server/middlewares/authorization.d.ts +2 -0
- package/dist/server/middlewares/authorization.js +42 -0
- package/dist/server/middlewares/oauth.d.ts +2 -0
- package/dist/server/middlewares/oauth.js +27 -0
- package/dist/server/middlewares/yt-auth.d.ts +1 -1
- package/dist/server/middlewares/yt-auth.js +10 -42
- package/dist/server/routes.js +6 -1
- package/dist/server/utils/authorization.d.ts +6 -0
- package/dist/server/utils/authorization.js +33 -0
- package/dist/shared/constants/index.d.ts +3 -0
- package/dist/shared/constants/index.js +3 -1
- package/package.json +2 -2
- package/dist/public/build/css/main.136a49c7.css.map +0 -1
- package/dist/public/build/js/89.6ea87438.chunk.js +0 -2
- package/dist/public/build/js/89.6ea87438.chunk.js.map +0 -1
- package/dist/public/build/js/main.f91e3651.js +0 -3
- /package/dist/public/build/js/{main.f91e3651.js.LICENSE.txt → main.9d592639.js.LICENSE.txt} +0 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
3
|
+
import axios from 'axios';
|
4
|
+
import { YT_OAUTH_ACCESS_TOKEN_NAME, YT_OAUTH_REFRESH_TOKEN_NAME } from '../../shared/constants';
|
5
|
+
export function isOAuthAllowed(req) {
|
6
|
+
var config = req.ctx.config.ytOAuthSettings;
|
7
|
+
return Boolean(config && config.baseURL && config.authPath && config.tokenPath && config.clientId && config.clientSecret);
|
8
|
+
}
|
9
|
+
export function getOAuthSettings(req) {
|
10
|
+
var config = req.ctx.config.ytOAuthSettings;
|
11
|
+
if (!config) {
|
12
|
+
throw new Error('OAuth settings is not specified');
|
13
|
+
}
|
14
|
+
return config;
|
15
|
+
}
|
16
|
+
|
17
|
+
// See https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.3.3
|
18
|
+
|
19
|
+
export function isUserOAuthLogged(req) {
|
20
|
+
return Boolean(req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME]) || Boolean(req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME]);
|
21
|
+
}
|
22
|
+
export function getOAuthAccessToken(_x, _x2) {
|
23
|
+
return _getOAuthAccessToken.apply(this, arguments);
|
24
|
+
}
|
25
|
+
function _getOAuthAccessToken() {
|
26
|
+
_getOAuthAccessToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, res) {
|
27
|
+
var tokens;
|
28
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
30
|
+
case 0:
|
31
|
+
if (!req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME]) {
|
32
|
+
_context.next = 4;
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
return _context.abrupt("return", req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME]);
|
36
|
+
case 4:
|
37
|
+
if (!req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME]) {
|
38
|
+
_context.next = 10;
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
_context.next = 7;
|
42
|
+
return refreshOAuthToken(req, req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME]);
|
43
|
+
case 7:
|
44
|
+
tokens = _context.sent;
|
45
|
+
saveOAuthTokensInCookies(res, tokens);
|
46
|
+
return _context.abrupt("return", tokens.access_token);
|
47
|
+
case 10:
|
48
|
+
return _context.abrupt("return", undefined);
|
49
|
+
case 11:
|
50
|
+
case "end":
|
51
|
+
return _context.stop();
|
52
|
+
}
|
53
|
+
}, _callee);
|
54
|
+
}));
|
55
|
+
return _getOAuthAccessToken.apply(this, arguments);
|
56
|
+
}
|
57
|
+
export function removeOAuthCookies(res) {
|
58
|
+
res.clearCookie(YT_OAUTH_ACCESS_TOKEN_NAME);
|
59
|
+
res.clearCookie(YT_OAUTH_REFRESH_TOKEN_NAME);
|
60
|
+
}
|
61
|
+
export function saveOAuthTokensInCookies(res, tokens) {
|
62
|
+
res.cookie(YT_OAUTH_ACCESS_TOKEN_NAME, tokens.access_token, {
|
63
|
+
maxAge: tokens.expires_in * 1000,
|
64
|
+
httpOnly: true,
|
65
|
+
secure: true
|
66
|
+
});
|
67
|
+
if (tokens.refresh_token) {
|
68
|
+
res.cookie(YT_OAUTH_REFRESH_TOKEN_NAME, tokens.refresh_token, {
|
69
|
+
maxAge: tokens.refresh_expires_in,
|
70
|
+
httpOnly: true,
|
71
|
+
secure: true
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
export function getOAuthLoginPath(req) {
|
76
|
+
var config = getOAuthSettings(req);
|
77
|
+
var host = req.get('host');
|
78
|
+
var params = new URLSearchParams({
|
79
|
+
response_type: 'code',
|
80
|
+
client_id: config.clientId,
|
81
|
+
scope: config.scope,
|
82
|
+
redirect_uri: "https://".concat(host, "/api/oauth/callback")
|
83
|
+
});
|
84
|
+
var url = new URL(config.authPath, config.baseURL);
|
85
|
+
url.search = params.toString();
|
86
|
+
return url.toString();
|
87
|
+
}
|
88
|
+
export function getOAuthLogoutPath(req) {
|
89
|
+
var config = getOAuthSettings(req);
|
90
|
+
var host = req.get('host');
|
91
|
+
var params = new URLSearchParams({
|
92
|
+
post_logout_redirect_uri: "https://".concat(host, "/api/oauth/logout/callback"),
|
93
|
+
client_id: config.clientId
|
94
|
+
});
|
95
|
+
var url = new URL(config.logoutPath, config.baseURL);
|
96
|
+
url.search = params.toString();
|
97
|
+
return url.toString();
|
98
|
+
}
|
99
|
+
export function refreshOAuthToken(_x3, _x4) {
|
100
|
+
return _refreshOAuthToken.apply(this, arguments);
|
101
|
+
}
|
102
|
+
function _refreshOAuthToken() {
|
103
|
+
_refreshOAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(req, token) {
|
104
|
+
var config, params, _yield$axios$post, data;
|
105
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
106
|
+
while (1) switch (_context2.prev = _context2.next) {
|
107
|
+
case 0:
|
108
|
+
config = getOAuthSettings(req);
|
109
|
+
params = new URLSearchParams({
|
110
|
+
grant_type: 'refresh_token',
|
111
|
+
client_id: config === null || config === void 0 ? void 0 : config.clientId,
|
112
|
+
refresh_token: token,
|
113
|
+
client_secret: config === null || config === void 0 ? void 0 : config.clientSecret
|
114
|
+
});
|
115
|
+
_context2.next = 4;
|
116
|
+
return axios.post(new URL(config.tokenPath, config.baseURL).toString(), params.toString(), {
|
117
|
+
headers: {
|
118
|
+
'Content-type': 'application/x-www-form-urlencoded'
|
119
|
+
}
|
120
|
+
});
|
121
|
+
case 4:
|
122
|
+
_yield$axios$post = _context2.sent;
|
123
|
+
data = _yield$axios$post.data;
|
124
|
+
return _context2.abrupt("return", data);
|
125
|
+
case 7:
|
126
|
+
case "end":
|
127
|
+
return _context2.stop();
|
128
|
+
}
|
129
|
+
}, _callee2);
|
130
|
+
}));
|
131
|
+
return _refreshOAuthToken.apply(this, arguments);
|
132
|
+
}
|
133
|
+
export function exchangeOAuthToken(_x5, _x6) {
|
134
|
+
return _exchangeOAuthToken.apply(this, arguments);
|
135
|
+
}
|
136
|
+
function _exchangeOAuthToken() {
|
137
|
+
_exchangeOAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(req, code) {
|
138
|
+
var config, host, params, _yield$axios$post2, data;
|
139
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
140
|
+
while (1) switch (_context3.prev = _context3.next) {
|
141
|
+
case 0:
|
142
|
+
config = getOAuthSettings(req);
|
143
|
+
host = req.get('host');
|
144
|
+
params = new URLSearchParams({
|
145
|
+
grant_type: 'authorization_code',
|
146
|
+
client_id: config.clientId,
|
147
|
+
code: code,
|
148
|
+
client_secret: config.clientSecret,
|
149
|
+
redirect_uri: "https://".concat(host, "/api/oauth/callback")
|
150
|
+
});
|
151
|
+
_context3.next = 5;
|
152
|
+
return axios.post(new URL(config.tokenPath, config.baseURL).toString(), params.toString(), {
|
153
|
+
headers: {
|
154
|
+
'Content-type': 'application/x-www-form-urlencoded'
|
155
|
+
}
|
156
|
+
});
|
157
|
+
case 5:
|
158
|
+
_yield$axios$post2 = _context3.sent;
|
159
|
+
data = _yield$axios$post2.data;
|
160
|
+
return _context3.abrupt("return", data);
|
161
|
+
case 8:
|
162
|
+
case "end":
|
163
|
+
return _context3.stop();
|
164
|
+
}
|
165
|
+
}, _callee3);
|
166
|
+
}));
|
167
|
+
return _exchangeOAuthToken.apply(this, arguments);
|
168
|
+
}
|
169
|
+
// #sourceMappingURL=oauth.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["axios","YT_OAUTH_ACCESS_TOKEN_NAME","YT_OAUTH_REFRESH_TOKEN_NAME","isOAuthAllowed","req","config","ctx","ytOAuthSettings","Boolean","baseURL","authPath","tokenPath","clientId","clientSecret","getOAuthSettings","Error","isUserOAuthLogged","cookies","getOAuthAccessToken","_x","_x2","_getOAuthAccessToken","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee","res","tokens","wrap","_callee$","_context","prev","next","abrupt","refreshOAuthToken","sent","saveOAuthTokensInCookies","access_token","undefined","stop","removeOAuthCookies","clearCookie","cookie","maxAge","expires_in","httpOnly","secure","refresh_token","refresh_expires_in","getOAuthLoginPath","host","get","params","URLSearchParams","response_type","client_id","scope","redirect_uri","concat","url","URL","search","toString","getOAuthLogoutPath","post_logout_redirect_uri","logoutPath","_x3","_x4","_refreshOAuthToken","_callee2","token","_yield$axios$post","data","_callee2$","_context2","grant_type","client_secret","post","headers","exchangeOAuthToken","_x5","_x6","_exchangeOAuthToken","_callee3","code","_yield$axios$post2","_callee3$","_context3"],"sources":["oauth.ts"],"sourcesContent":["import axios from 'axios';\nimport type {Request, Response} from 'express';\nimport {YT_OAUTH_ACCESS_TOKEN_NAME, YT_OAUTH_REFRESH_TOKEN_NAME} from '../../shared/constants';\n\nexport function isOAuthAllowed(req: Request) {\n const config = req.ctx.config.ytOAuthSettings;\n return Boolean(\n config &&\n config.baseURL &&\n config.authPath &&\n config.tokenPath &&\n config.clientId &&\n config.clientSecret,\n );\n}\n\nexport function getOAuthSettings(req: Request) {\n const config = req.ctx.config.ytOAuthSettings;\n if (!config) {\n throw new Error('OAuth settings is not specified');\n }\n return config;\n}\n\n// See https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.3.3\nexport type OAuthAuthorizationTokens = {\n access_token: string;\n expires_in: number;\n refresh_token: string;\n refresh_expires_in: number;\n};\n\nexport function isUserOAuthLogged(req: Request) {\n return (\n Boolean(req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME]) ||\n Boolean(req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME])\n );\n}\n\nexport async function getOAuthAccessToken(req: Request, res: Response) {\n if (req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME]) {\n return req.cookies[YT_OAUTH_ACCESS_TOKEN_NAME];\n } else if (req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME]) {\n const tokens = await refreshOAuthToken(\n req,\n req.cookies[YT_OAUTH_REFRESH_TOKEN_NAME] as string,\n );\n saveOAuthTokensInCookies(res, tokens);\n return tokens.access_token;\n }\n return undefined;\n}\n\nexport function removeOAuthCookies(res: Response) {\n res.clearCookie(YT_OAUTH_ACCESS_TOKEN_NAME);\n res.clearCookie(YT_OAUTH_REFRESH_TOKEN_NAME);\n}\n\nexport function saveOAuthTokensInCookies(res: Response, tokens: OAuthAuthorizationTokens) {\n res.cookie(YT_OAUTH_ACCESS_TOKEN_NAME, tokens.access_token, {\n maxAge: tokens.expires_in * 1000,\n httpOnly: true,\n secure: true,\n });\n\n if (tokens.refresh_token) {\n res.cookie(YT_OAUTH_REFRESH_TOKEN_NAME, tokens.refresh_token, {\n maxAge: tokens.refresh_expires_in,\n httpOnly: true,\n secure: true,\n });\n }\n}\n\nexport function getOAuthLoginPath(req: Request) {\n const config = getOAuthSettings(req);\n const host = req.get('host');\n const params = new URLSearchParams({\n response_type: 'code',\n client_id: config.clientId,\n scope: config.scope,\n redirect_uri: `https://${host}/api/oauth/callback`,\n });\n\n const url = new URL(config.authPath, config.baseURL);\n url.search = params.toString();\n\n return url.toString();\n}\n\nexport function getOAuthLogoutPath(req: Request) {\n const config = getOAuthSettings(req);\n const host = req.get('host');\n const params = new URLSearchParams({\n post_logout_redirect_uri: `https://${host}/api/oauth/logout/callback`,\n client_id: config.clientId,\n });\n\n const url = new URL(config.logoutPath, config.baseURL);\n url.search = params.toString();\n\n return url.toString();\n}\n\nexport async function refreshOAuthToken(\n req: Request,\n token: string,\n): Promise<OAuthAuthorizationTokens> {\n const config = getOAuthSettings(req);\n const params = new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: config?.clientId,\n refresh_token: token,\n client_secret: config?.clientSecret,\n });\n const {data} = await axios.post(\n new URL(config.tokenPath, config.baseURL).toString(),\n params.toString(),\n {\n headers: {\n 'Content-type': 'application/x-www-form-urlencoded',\n },\n },\n );\n return data;\n}\n\nexport async function exchangeOAuthToken(\n req: Request,\n code: string,\n): Promise<OAuthAuthorizationTokens> {\n const config = getOAuthSettings(req);\n const host = req.get('host');\n const params = new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: config.clientId,\n code: code as string,\n client_secret: config.clientSecret,\n redirect_uri: `https://${host}/api/oauth/callback`,\n });\n\n const {data} = await axios.post(\n new URL(config.tokenPath, config.baseURL).toString(),\n params.toString(),\n {\n headers: {\n 'Content-type': 'application/x-www-form-urlencoded',\n },\n },\n );\n return data;\n}\n"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,0BAA0B,EAAEC,2BAA2B,QAAO,wBAAwB;AAE9F,OAAO,SAASC,cAAcA,CAACC,GAAY,EAAE;EACzC,IAAMC,MAAM,GAAGD,GAAG,CAACE,GAAG,CAACD,MAAM,CAACE,eAAe;EAC7C,OAAOC,OAAO,CACVH,MAAM,IACFA,MAAM,CAACI,OAAO,IACdJ,MAAM,CAACK,QAAQ,IACfL,MAAM,CAACM,SAAS,IAChBN,MAAM,CAACO,QAAQ,IACfP,MAAM,CAACQ,YACf,CAAC;AACL;AAEA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AAAxD,IAAA,GAAAwD,SAAA,CAAAvD,IAAA;QAAA;UAEN7B,MAAM,GAAGS,gBAAgB,CAACV,GAAG,CAAC;UAC9BgD,IAAI,GAAGhD,GAAG,CAACiD,GAAG,CAAC,MAAM,CAAC;UACtBC,MAAM,GAAG,IAAIC,eAAe,CAAC;YAC/BsB,UAAU,EAAE,oBAAoB;YAChCpB,SAAS,EAAEpD,MAAM,CAACO,QAAQ;YAC1B0E,IAAI,EAAEA,IAAc;YACpBR,aAAa,EAAEzE,MAAM,CAACQ,YAAY;YAClC8C,YAAY,aAAAC,MAAA,CAAaR,IAAI;UACjC,CAAC,CAAC;UAAAqC,SAAA,CAAAvD,IAAA;UAAA,OAEmBlC,KAAK,CAAC+E,IAAI,CAC3B,IAAIjB,GAAG,CAACzD,MAAM,CAACM,SAAS,EAAEN,MAAM,CAACI,OAAO,CAAC,CAACuD,QAAQ,CAAC,CAAC,EACpDV,MAAM,CAACU,QAAQ,CAAC,CAAC,EACjB;YACIgB,OAAO,EAAE;cACL,cAAc,EAAE;YACpB;UACJ,CACJ,CAAC;QAAA;UAAAO,kBAAA,GAAAE,SAAA,CAAApD,IAAA;UARMqC,IAAI,GAAAa,kBAAA,CAAJb,IAAI;UAAA,OAAAe,SAAA,CAAAtD,MAAA,WASJuC,IAAI;QAAA;QAAA;UAAA,OAAAe,SAAA,CAAAhD,IAAA;MAAA;IAAA,GAAA4C,QAAA;EAAA,CACd;EAAA,OAAAD,mBAAA,CAAA9D,KAAA,OAAAC,SAAA;AAAA"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { AppConfig } from '@gravity-ui/nodekit';
|
2
|
+
import type { Response } from 'express';
|
3
|
+
export declare function isYtAuthEnabled(config: AppConfig): boolean;
|
4
|
+
export declare function assertAuthEnabled(ytAuthCluster?: string): asserts ytAuthCluster is string;
|
5
|
+
export declare function getAuthCluster(config: AppConfig): string;
|
6
|
+
export declare function YTAuthLogout(res: Response): void;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { YT_CYPRESS_COOKIE_NAME } from '../../shared/constants';
|
2
|
+
export function isYtAuthEnabled(config) {
|
3
|
+
return Boolean(config.ytAuthCluster);
|
4
|
+
}
|
5
|
+
export function assertAuthEnabled(ytAuthCluster) {
|
6
|
+
if (!ytAuthCluster) {
|
7
|
+
throw new Error('Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.');
|
8
|
+
}
|
9
|
+
}
|
10
|
+
export function getAuthCluster(config) {
|
11
|
+
assertAuthEnabled(config.ytAuthCluster);
|
12
|
+
return config.ytAuthCluster;
|
13
|
+
}
|
14
|
+
export function YTAuthLogout(res) {
|
15
|
+
res.setHeader('set-cookie', "".concat(YT_CYPRESS_COOKIE_NAME, "=deleted; Path=/; Max-Age=0;"));
|
16
|
+
}
|
17
|
+
// #sourceMappingURL=yt-auth.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["YT_CYPRESS_COOKIE_NAME","isYtAuthEnabled","config","Boolean","ytAuthCluster","assertAuthEnabled","Error","getAuthCluster","YTAuthLogout","res","setHeader","concat"],"sources":["yt-auth.ts"],"sourcesContent":["import {AppConfig} from '@gravity-ui/nodekit';\nimport type {Response} from 'express';\nimport {YT_CYPRESS_COOKIE_NAME} from '../../shared/constants';\n\nexport function isYtAuthEnabled(config: AppConfig) {\n return Boolean(config.ytAuthCluster);\n}\n\nexport function assertAuthEnabled(ytAuthCluster?: string): asserts ytAuthCluster is string {\n if (!ytAuthCluster) {\n throw new Error(\n 'Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.',\n );\n }\n}\n\nexport function getAuthCluster(config: AppConfig) {\n assertAuthEnabled(config.ytAuthCluster);\n return config.ytAuthCluster;\n}\n\nexport function YTAuthLogout(res: Response) {\n res.setHeader('set-cookie', `${YT_CYPRESS_COOKIE_NAME}=deleted; Path=/; Max-Age=0;`);\n}\n"],"mappings":"AAEA,SAAQA,sBAAsB,QAAO,wBAAwB;AAE7D,OAAO,SAASC,eAAeA,CAACC,MAAiB,EAAE;EAC/C,OAAOC,OAAO,CAACD,MAAM,CAACE,aAAa,CAAC;AACxC;AAEA,OAAO,SAASC,iBAAiBA,CAACD,aAAsB,EAAmC;EACvF,IAAI,CAACA,aAAa,EAAE;IAChB,MAAM,IAAIE,KAAK,CACX,8FACJ,CAAC;EACL;AACJ;AAEA,OAAO,SAASC,cAAcA,CAACL,MAAiB,EAAE;EAC9CG,iBAAiB,CAACH,MAAM,CAACE,aAAa,CAAC;EACvC,OAAOF,MAAM,CAACE,aAAa;AAC/B;AAEA,OAAO,SAASI,YAAYA,CAACC,GAAa,EAAE;EACxCA,GAAG,CAACC,SAAS,CAAC,YAAY,KAAAC,MAAA,CAAKX,sBAAsB,iCAA8B,CAAC;AACxF"}
|
@@ -1,4 +1,3 @@
|
|
1
1
|
import type { Request, Response } from 'express';
|
2
2
|
export declare function handleLogin(req: Request, res: Response): Promise<void>;
|
3
|
-
export declare function handleLogout(req: Request, res: Response): Promise<void>;
|
4
3
|
export declare function handleChangePassword(req: Request, res: Response): Promise<void>;
|
@@ -12,10 +12,8 @@ import crypto from 'crypto';
|
|
12
12
|
// @ts-ignore
|
13
13
|
import ytLib from '@ytsaurus/javascript-wrapper';
|
14
14
|
import { getXSRFToken } from '../components/cluster-queries';
|
15
|
+
import { getAuthCluster } from '../components/yt-auth';
|
15
16
|
var yt = ytLib();
|
16
|
-
function throwAuthDisabled() {
|
17
|
-
throw new Error('Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.');
|
18
|
-
}
|
19
17
|
export function handleLogin(_x, _x2) {
|
20
18
|
return _handleLogin.apply(this, arguments);
|
21
19
|
}
|
@@ -26,24 +24,18 @@ function _handleLogin() {
|
|
26
24
|
while (1) switch (_context2.prev = _context2.next) {
|
27
25
|
case 0:
|
28
26
|
_context2.prev = 0;
|
29
|
-
ytAuthCluster = req.ctx.config
|
30
|
-
if (ytAuthCluster) {
|
31
|
-
_context2.next = 4;
|
32
|
-
break;
|
33
|
-
}
|
34
|
-
return _context2.abrupt("return", throwAuthDisabled());
|
35
|
-
case 4:
|
27
|
+
ytAuthCluster = getAuthCluster(req.ctx.config);
|
36
28
|
_ref = JSON.parse(req.body) || {}, username = _ref.username, password = _ref.password;
|
37
29
|
if (!(!username || !password)) {
|
38
|
-
_context2.next =
|
30
|
+
_context2.next = 5;
|
39
31
|
break;
|
40
32
|
}
|
41
33
|
throw new Error('Username and password must not be empty');
|
42
|
-
case
|
34
|
+
case 5:
|
43
35
|
_getYTApiClusterSetup = getYTApiClusterSetup(ytAuthCluster), proxyBaseUrl = _getYTApiClusterSetup.proxyBaseUrl;
|
44
36
|
requestUrl = "".concat(proxyBaseUrl, "/login");
|
45
37
|
basicAuth = Buffer.from("".concat(username, ":").concat(password)).toString('base64');
|
46
|
-
_context2.next =
|
38
|
+
_context2.next = 10;
|
47
39
|
return axios.request({
|
48
40
|
url: requestUrl,
|
49
41
|
method: req.method,
|
@@ -75,22 +67,22 @@ function _handleLogin() {
|
|
75
67
|
}
|
76
68
|
}, _callee);
|
77
69
|
}));
|
78
|
-
return function (
|
70
|
+
return function (_x5) {
|
79
71
|
return _ref2.apply(this, arguments);
|
80
72
|
};
|
81
73
|
}());
|
82
|
-
case
|
83
|
-
_context2.next =
|
74
|
+
case 10:
|
75
|
+
_context2.next = 15;
|
84
76
|
break;
|
85
|
-
case
|
86
|
-
_context2.prev =
|
77
|
+
case 12:
|
78
|
+
_context2.prev = 12;
|
87
79
|
_context2.t0 = _context2["catch"](0);
|
88
80
|
sendAndLogError(req.ctx, res, 500, _context2.t0);
|
89
|
-
case
|
81
|
+
case 15:
|
90
82
|
case "end":
|
91
83
|
return _context2.stop();
|
92
84
|
}
|
93
|
-
}, _callee2, null, [[0,
|
85
|
+
}, _callee2, null, [[0, 12]]);
|
94
86
|
}));
|
95
87
|
return _handleLogin.apply(this, arguments);
|
96
88
|
}
|
@@ -115,86 +107,47 @@ function removeSecureFlagIfOriginInsecure(req, headers) {
|
|
115
107
|
return acc;
|
116
108
|
}, {});
|
117
109
|
}
|
118
|
-
export function
|
119
|
-
return _handleLogout.apply(this, arguments);
|
120
|
-
}
|
121
|
-
function _handleLogout() {
|
122
|
-
_handleLogout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(req, res) {
|
123
|
-
var ytAuthCluster;
|
124
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
125
|
-
while (1) switch (_context3.prev = _context3.next) {
|
126
|
-
case 0:
|
127
|
-
_context3.prev = 0;
|
128
|
-
ytAuthCluster = req.ctx.config.ytAuthCluster;
|
129
|
-
if (ytAuthCluster) {
|
130
|
-
_context3.next = 4;
|
131
|
-
break;
|
132
|
-
}
|
133
|
-
return _context3.abrupt("return", throwAuthDisabled());
|
134
|
-
case 4:
|
135
|
-
res.setHeader('set-cookie', "".concat(YT_CYPRESS_COOKIE_NAME, "=deleted; Path=/; Max-Age=0;"));
|
136
|
-
res.status(401).send('Logout');
|
137
|
-
_context3.next = 11;
|
138
|
-
break;
|
139
|
-
case 8:
|
140
|
-
_context3.prev = 8;
|
141
|
-
_context3.t0 = _context3["catch"](0);
|
142
|
-
sendAndLogError(req.ctx, res, 500, _context3.t0);
|
143
|
-
case 11:
|
144
|
-
case "end":
|
145
|
-
return _context3.stop();
|
146
|
-
}
|
147
|
-
}, _callee3, null, [[0, 8]]);
|
148
|
-
}));
|
149
|
-
return _handleLogout.apply(this, arguments);
|
150
|
-
}
|
151
|
-
export function handleChangePassword(_x5, _x6) {
|
110
|
+
export function handleChangePassword(_x3, _x4) {
|
152
111
|
return _handleChangePassword.apply(this, arguments);
|
153
112
|
}
|
154
113
|
function _handleChangePassword() {
|
155
|
-
_handleChangePassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
114
|
+
_handleChangePassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(req, res) {
|
156
115
|
var ytAuthCluster, _ref3, newPassword, currentPassword, new_password_sha256, current_password_sha256, cfg, _cfg, setup, _yield$getXSRFToken, login, csrf_token;
|
157
|
-
return _regeneratorRuntime.wrap(function
|
158
|
-
while (1) switch (
|
116
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
117
|
+
while (1) switch (_context3.prev = _context3.next) {
|
159
118
|
case 0:
|
160
|
-
|
161
|
-
ytAuthCluster = req.ctx.config
|
162
|
-
if (ytAuthCluster) {
|
163
|
-
_context4.next = 4;
|
164
|
-
break;
|
165
|
-
}
|
166
|
-
return _context4.abrupt("return", throwAuthDisabled());
|
167
|
-
case 4:
|
119
|
+
_context3.prev = 0;
|
120
|
+
ytAuthCluster = getAuthCluster(req.ctx.config);
|
168
121
|
_ref3 = JSON.parse(req.body) || {}, newPassword = _ref3.newPassword, currentPassword = _ref3.currentPassword;
|
169
122
|
if (!(!newPassword || !currentPassword)) {
|
170
|
-
|
123
|
+
_context3.next = 5;
|
171
124
|
break;
|
172
125
|
}
|
173
126
|
throw new Error('New and current password must not be empty');
|
174
|
-
case
|
127
|
+
case 5:
|
175
128
|
new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');
|
176
129
|
current_password_sha256 = crypto.createHash('sha256').update(currentPassword).digest('hex');
|
177
|
-
|
130
|
+
_context3.prev = 7;
|
178
131
|
cfg = getUserYTApiSetup(ytAuthCluster, req);
|
179
|
-
|
132
|
+
_context3.next = 15;
|
180
133
|
break;
|
181
|
-
case
|
182
|
-
|
183
|
-
|
184
|
-
sendAndLogError(req.ctx, res, 400,
|
185
|
-
return
|
186
|
-
case
|
134
|
+
case 11:
|
135
|
+
_context3.prev = 11;
|
136
|
+
_context3.t0 = _context3["catch"](7);
|
137
|
+
sendAndLogError(req.ctx, res, 400, _context3.t0);
|
138
|
+
return _context3.abrupt("return");
|
139
|
+
case 15:
|
187
140
|
_cfg = cfg, setup = _cfg.setup;
|
188
|
-
|
141
|
+
_context3.next = 18;
|
189
142
|
return getXSRFToken(req, cfg);
|
190
|
-
case
|
191
|
-
_yield$getXSRFToken =
|
143
|
+
case 18:
|
144
|
+
_yield$getXSRFToken = _context3.sent;
|
192
145
|
login = _yield$getXSRFToken.login;
|
193
146
|
csrf_token = _yield$getXSRFToken.csrf_token;
|
194
147
|
yt.setup.createOption('requestHeaders', 'object', {
|
195
148
|
'X-Csrf-Token': csrf_token
|
196
149
|
});
|
197
|
-
|
150
|
+
_context3.next = 24;
|
198
151
|
return yt.v4.setUserPassword({
|
199
152
|
setup: setup,
|
200
153
|
parameters: {
|
@@ -209,18 +162,18 @@ function _handleChangePassword() {
|
|
209
162
|
})["catch"](function (err) {
|
210
163
|
sendAndLogError(req.ctx, res, 500, err);
|
211
164
|
});
|
212
|
-
case
|
213
|
-
|
165
|
+
case 24:
|
166
|
+
_context3.next = 29;
|
214
167
|
break;
|
215
|
-
case
|
216
|
-
|
217
|
-
|
218
|
-
sendAndLogError(req.ctx, res, 500,
|
219
|
-
case
|
168
|
+
case 26:
|
169
|
+
_context3.prev = 26;
|
170
|
+
_context3.t1 = _context3["catch"](0);
|
171
|
+
sendAndLogError(req.ctx, res, 500, _context3.t1);
|
172
|
+
case 29:
|
220
173
|
case "end":
|
221
|
-
return
|
174
|
+
return _context3.stop();
|
222
175
|
}
|
223
|
-
},
|
176
|
+
}, _callee3, null, [[0, 26], [7, 11]]);
|
224
177
|
}));
|
225
178
|
return _handleChangePassword.apply(this, arguments);
|
226
179
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["axios","YT_CYPRESS_COOKIE_NAME","getUserYTApiSetup","getYTApiClusterSetup","UNEXPECTED_PIPE_AXIOS_RESPONSE","pipeAxiosResponse","sendAndLogError","crypto","ytLib","getXSRFToken","yt","throwAuthDisabled","Error","handleLogin","_x","_x2","_handleLogin","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","req","res","ytAuthCluster","_ref","username","password","_getYTApiClusterSetup","proxyBaseUrl","requestUrl","basicAuth","wrap","_callee2$","_context2","prev","next","ctx","config","abrupt","JSON","parse","body","concat","Buffer","from","toString","request","url","method","headers","_objectSpread","getMetadata","Authorization","timeout","responseType","then","_ref2","_callee","response","pipedSize","_callee$","_context","undefined","removeSecureFlagIfOriginInsecure","sent","stop","_x7","t0","ytAuthAllowInsecure","origin","startsWith","_reduce","acc","v","k","tmp","_map","item","replace","handleLogout","_x3","_x4","_handleLogout","_callee3","_callee3$","_context3","setHeader","status","send","handleChangePassword","_x5","_x6","_handleChangePassword","_callee4","_ref3","newPassword","currentPassword","new_password_sha256","current_password_sha256","cfg","_cfg","setup","_yield$getXSRFToken","login","csrf_token","_callee4$","_context4","createHash","update","digest","createOption","v4","setUserPassword","parameters","user","result","err","t1"],"sources":["login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport axios from 'axios';\nimport _ from 'lodash';\nimport {YT_CYPRESS_COOKIE_NAME} from '../../shared/constants';\nimport {getUserYTApiSetup, getYTApiClusterSetup} from '../components/requestsSetup';\nimport {UNEXPECTED_PIPE_AXIOS_RESPONSE, pipeAxiosResponse, sendAndLogError} from '../utils';\nimport crypto from 'crypto';\n\n// @ts-ignore\nimport ytLib from '@ytsaurus/javascript-wrapper';\nimport {getXSRFToken} from '../components/cluster-queries';\n\nconst yt = ytLib();\n\nfunction throwAuthDisabled() {\n throw new Error(\n 'Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.',\n );\n}\n\nexport async function handleLogin(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n\n const {username, password} = JSON.parse(req.body) || {};\n if (!username || !password) {\n throw new Error('Username and password must not be empty');\n }\n\n const {proxyBaseUrl} = getYTApiClusterSetup(ytAuthCluster);\n const requestUrl = `${proxyBaseUrl}/login`;\n\n const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');\n\n await axios\n .request({\n url: requestUrl,\n method: req.method as any,\n headers: {...req.ctx.getMetadata(), Authorization: `Basic ${basicAuth}`},\n timeout: 10000,\n responseType: 'stream',\n })\n .then(async (response) => {\n const pipedSize = await pipeAxiosResponse(\n req.ctx,\n res,\n response,\n undefined,\n (headers) => removeSecureFlagIfOriginInsecure(req, headers),\n );\n if (!pipedSize) {\n throw new Error(UNEXPECTED_PIPE_AXIOS_RESPONSE);\n }\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nfunction removeSecureFlagIfOriginInsecure(\n req: Request,\n headers: Record<string, string | Array<string>>,\n) {\n const {ytAuthAllowInsecure} = req.ctx.config;\n const {origin} = req.headers;\n\n if (!ytAuthAllowInsecure || 'string' !== typeof origin || !origin.startsWith('http://')) {\n return headers;\n }\n\n return _.reduce(\n headers,\n (acc, v, k) => {\n if (k !== 'set-cookie') {\n acc[k] = v;\n } else {\n const tmp = _.map(v as Array<string>, (item) => {\n if (item.startsWith(YT_CYPRESS_COOKIE_NAME)) {\n return item.replace(/\\s*Secure;/, '');\n }\n return item;\n });\n acc[k] = tmp;\n }\n return acc;\n },\n {} as typeof headers,\n );\n}\n\nexport async function handleLogout(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n res.setHeader('set-cookie', `${YT_CYPRESS_COOKIE_NAME}=deleted; Path=/; Max-Age=0;`);\n res.status(401).send('Logout');\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nexport async function handleChangePassword(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n\n const {newPassword, currentPassword} = JSON.parse(req.body) || {};\n if (!newPassword || !currentPassword) {\n throw new Error('New and current password must not be empty');\n }\n\n const new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');\n const current_password_sha256 = crypto\n .createHash('sha256')\n .update(currentPassword)\n .digest('hex');\n\n let cfg;\n try {\n cfg = getUserYTApiSetup(ytAuthCluster, req);\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 400, e);\n return;\n }\n\n const {setup} = cfg;\n const {login, csrf_token} = await getXSRFToken(req, cfg);\n\n yt.setup.createOption('requestHeaders', 'object', {\n 'X-Csrf-Token': csrf_token,\n });\n\n await yt.v4\n .setUserPassword({\n setup,\n parameters: {user: login, new_password_sha256, current_password_sha256},\n })\n .then((result: unknown) => {\n res.status(200).send({result});\n })\n .catch((err: any) => {\n sendAndLogError(req.ctx, res, 500, err);\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n"],"mappings":";;;;;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,sBAAsB,QAAO,wBAAwB;AAC7D,SAAQC,iBAAiB,EAAEC,oBAAoB,QAAO,6BAA6B;AACnF,SAAQC,8BAA8B,EAAEC,iBAAiB,EAAEC,eAAe,QAAO,UAAU;AAC3F,OAAOC,MAAM,MAAM,QAAQ;;AAE3B;AACA,OAAOC,KAAK,MAAM,8BAA8B;AAChD,SAAQC,YAAY,QAAO,+BAA+B;AAE1D,IAAMC,EAAE,GAAGF,KAAK,CAAC,CAAC;AAElB,SAASG,iBAAiBA,CAAA,EAAG;EACzB,MAAM,IAAIC,KAAK,CACX,8FACJ,CAAC;AACL;AAEA,gBAAsBC,WAAWA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,YAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAwChC,SAAAF,aAAA;EAAAA,YAAA,GAAAG,iBAAA,eAAAC,mBAAA,CAAAC,IAAA,CAxCM,SAAAC,SAA2BC,GAAY,EAAEC,GAAa;IAAA,IAAAC,aAAA,EAAAC,IAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,qBAAA,EAAAC,YAAA,EAAAC,UAAA,EAAAC,SAAA;IAAA,OAAAZ,mBAAA,CAAAa,IAAA,UAAAC,UAAAC,SAAA;MAAA,kBAAAA,SAAA,CAAAC,IAAA,GAAAD,SAAA,CAAAE,IAAA;QAAA;UAAAF,SAAA,CAAAC,IAAA;UAE9CX,aAAa,GA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E,CAAC6F,KAAK,CAACS,YAAY,CAAC,gBAAgB,EAAE,QAAQ,EAAE;YAC9C,cAAc,EAAEN;UACpB,CAAC,CAAC;UAACE,SAAA,CAAAvE,IAAA;UAAA,OAEG3B,EAAE,CAACuG,EAAE,CACNC,eAAe,CAAC;YACbX,KAAK,EAALA,KAAK;YACLY,UAAU,EAAE;cAACC,IAAI,EAAEX,KAAK;cAAEN,mBAAmB,EAAnBA,mBAAmB;cAAEC,uBAAuB,EAAvBA;YAAuB;UAC1E,CAAC,CAAC,CACD3C,IAAI,CAAC,UAAC4D,MAAe,EAAK;YACvB7F,GAAG,CAACiE,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAC2B,MAAM,EAANA;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,SACI,CAAC,UAACC,GAAQ,EAAK;YACjBhH,eAAe,CAACiB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAE8F,GAAG,CAAC;UAC3C,CAAC,CAAC;QAAA;UAAAV,SAAA,CAAAvE,IAAA;UAAA;QAAA;UAAAuE,SAAA,CAAAxE,IAAA;UAAAwE,SAAA,CAAAW,EAAA,GAAAX,SAAA;UAENtG,eAAe,CAACiB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAAoF,SAAA,CAAAW,EAAG,CAAC;QAAC;QAAA;UAAA,OAAAX,SAAA,CAAAzC,IAAA;MAAA;IAAA,GAAA4B,QAAA;EAAA,CAE7C;EAAA,OAAAD,qBAAA,CAAA7E,KAAA,OAAAC,SAAA;AAAA"}
|
1
|
+
{"version":3,"names":["axios","YT_CYPRESS_COOKIE_NAME","getUserYTApiSetup","getYTApiClusterSetup","UNEXPECTED_PIPE_AXIOS_RESPONSE","pipeAxiosResponse","sendAndLogError","crypto","ytLib","getXSRFToken","getAuthCluster","yt","handleLogin","_x","_x2","_handleLogin","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","req","res","ytAuthCluster","_ref","username","password","_getYTApiClusterSetup","proxyBaseUrl","requestUrl","basicAuth","wrap","_callee2$","_context2","prev","next","ctx","config","JSON","parse","body","Error","concat","Buffer","from","toString","request","url","method","headers","_objectSpread","getMetadata","Authorization","timeout","responseType","then","_ref2","_callee","response","pipedSize","_callee$","_context","undefined","removeSecureFlagIfOriginInsecure","sent","stop","_x5","t0","ytAuthAllowInsecure","origin","startsWith","_reduce","acc","v","k","tmp","_map","item","replace","handleChangePassword","_x3","_x4","_handleChangePassword","_callee3","_ref3","newPassword","currentPassword","new_password_sha256","current_password_sha256","cfg","_cfg","setup","_yield$getXSRFToken","login","csrf_token","_callee3$","_context3","createHash","update","digest","abrupt","createOption","v4","setUserPassword","parameters","user","result","status","send","err","t1"],"sources":["login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport axios from 'axios';\nimport _ from 'lodash';\nimport {YT_CYPRESS_COOKIE_NAME} from '../../shared/constants';\nimport {getUserYTApiSetup, getYTApiClusterSetup} from '../components/requestsSetup';\nimport {UNEXPECTED_PIPE_AXIOS_RESPONSE, pipeAxiosResponse, sendAndLogError} from '../utils';\nimport crypto from 'crypto';\n\n// @ts-ignore\nimport ytLib from '@ytsaurus/javascript-wrapper';\nimport {getXSRFToken} from '../components/cluster-queries';\nimport {getAuthCluster} from '../components/yt-auth';\n\nconst yt = ytLib();\n\nexport async function handleLogin(req: Request, res: Response) {\n try {\n const ytAuthCluster = getAuthCluster(req.ctx.config);\n\n const {username, password} = JSON.parse(req.body) || {};\n if (!username || !password) {\n throw new Error('Username and password must not be empty');\n }\n\n const {proxyBaseUrl} = getYTApiClusterSetup(ytAuthCluster);\n const requestUrl = `${proxyBaseUrl}/login`;\n\n const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');\n\n await axios\n .request({\n url: requestUrl,\n method: req.method as any,\n headers: {...req.ctx.getMetadata(), Authorization: `Basic ${basicAuth}`},\n timeout: 10000,\n responseType: 'stream',\n })\n .then(async (response) => {\n const pipedSize = await pipeAxiosResponse(\n req.ctx,\n res,\n response,\n undefined,\n (headers) => removeSecureFlagIfOriginInsecure(req, headers),\n );\n if (!pipedSize) {\n throw new Error(UNEXPECTED_PIPE_AXIOS_RESPONSE);\n }\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nfunction removeSecureFlagIfOriginInsecure(\n req: Request,\n headers: Record<string, string | Array<string>>,\n) {\n const {ytAuthAllowInsecure} = req.ctx.config;\n const {origin} = req.headers;\n\n if (!ytAuthAllowInsecure || 'string' !== typeof origin || !origin.startsWith('http://')) {\n return headers;\n }\n\n return _.reduce(\n headers,\n (acc, v, k) => {\n if (k !== 'set-cookie') {\n acc[k] = v;\n } else {\n const tmp = _.map(v as Array<string>, (item) => {\n if (item.startsWith(YT_CYPRESS_COOKIE_NAME)) {\n return item.replace(/\\s*Secure;/, '');\n }\n return item;\n });\n acc[k] = tmp;\n }\n return acc;\n },\n {} as typeof headers,\n );\n}\n\nexport async function handleChangePassword(req: Request, res: Response) {\n try {\n const ytAuthCluster = getAuthCluster(req.ctx.config);\n\n const {newPassword, currentPassword} = JSON.parse(req.body) || {};\n if (!newPassword || !currentPassword) {\n throw new Error('New and current password must not be empty');\n }\n\n const new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');\n const current_password_sha256 = crypto\n .createHash('sha256')\n .update(currentPassword)\n .digest('hex');\n\n let cfg;\n try {\n cfg = getUserYTApiSetup(ytAuthCluster, req);\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 400, e);\n return;\n }\n\n const {setup} = cfg;\n const {login, csrf_token} = await getXSRFToken(req, cfg);\n\n yt.setup.createOption('requestHeaders', 'object', {\n 'X-Csrf-Token': csrf_token,\n });\n\n await yt.v4\n .setUserPassword({\n setup,\n parameters: {user: login, new_password_sha256, current_password_sha256},\n })\n .then((result: unknown) => {\n res.status(200).send({result});\n })\n .catch((err: any) => {\n sendAndLogError(req.ctx, res, 500, err);\n });\n } catch (e: any) {\n sendAndLogError(req.ctx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;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,SACI,CAAC,UAACG,GAAQ,EAAK;YACjBxG,eAAe,CAACgB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAEuF,GAAG,CAAC;UAC3C,CAAC,CAAC;QAAA;UAAAb,SAAA,CAAA7D,IAAA;UAAA;QAAA;UAAA6D,SAAA,CAAA9D,IAAA;UAAA8D,SAAA,CAAAc,EAAA,GAAAd,SAAA;UAEN3F,eAAe,CAACgB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAA0E,SAAA,CAAAc,EAAG,CAAC;QAAC;QAAA;UAAA,OAAAd,SAAA,CAAA/B,IAAA;MAAA;IAAA,GAAAkB,QAAA;EAAA,CAE7C;EAAA,OAAAD,qBAAA,CAAAnE,KAAA,OAAAC,SAAA;AAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { getOAuthLogoutPath, isOAuthAllowed, isUserOAuthLogged } from '../components/oauth';
|
2
|
+
import { YTAuthLogout, isYtAuthEnabled } from '../components/yt-auth';
|
3
|
+
export function handleLogout(req, res) {
|
4
|
+
if (isOAuthAllowed(req) && isUserOAuthLogged(req)) {
|
5
|
+
res.redirect(getOAuthLogoutPath(req));
|
6
|
+
} else if (isYtAuthEnabled(req.ctx.config)) {
|
7
|
+
YTAuthLogout(res);
|
8
|
+
}
|
9
|
+
res.redirect('/');
|
10
|
+
}
|
11
|
+
// #sourceMappingURL=logout.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["getOAuthLogoutPath","isOAuthAllowed","isUserOAuthLogged","YTAuthLogout","isYtAuthEnabled","handleLogout","req","res","redirect","ctx","config"],"sources":["logout.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport {getOAuthLogoutPath, isOAuthAllowed, isUserOAuthLogged} from '../components/oauth';\nimport {YTAuthLogout, isYtAuthEnabled} from '../components/yt-auth';\n\nexport function handleLogout(req: Request, res: Response) {\n if (isOAuthAllowed(req) && isUserOAuthLogged(req)) {\n res.redirect(getOAuthLogoutPath(req));\n } else if (isYtAuthEnabled(req.ctx.config)) {\n YTAuthLogout(res);\n }\n res.redirect('/');\n}\n"],"mappings":"AACA,SAAQA,kBAAkB,EAAEC,cAAc,EAAEC,iBAAiB,QAAO,qBAAqB;AACzF,SAAQC,YAAY,EAAEC,eAAe,QAAO,uBAAuB;AAEnE,OAAO,SAASC,YAAYA,CAACC,GAAY,EAAEC,GAAa,EAAE;EACtD,IAAIN,cAAc,CAACK,GAAG,CAAC,IAAIJ,iBAAiB,CAACI,GAAG,CAAC,EAAE;IAC/CC,GAAG,CAACC,QAAQ,CAACR,kBAAkB,CAACM,GAAG,CAAC,CAAC;EACzC,CAAC,MAAM,IAAIF,eAAe,CAACE,GAAG,CAACG,GAAG,CAACC,MAAM,CAAC,EAAE;IACxCP,YAAY,CAACI,GAAG,CAAC;EACrB;EACAA,GAAG,CAACC,QAAQ,CAAC,GAAG,CAAC;AACrB"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { Request, Response } from 'express';
|
2
|
+
export declare function oauthLogin(req: Request, res: Response): void;
|
3
|
+
export declare function oauthLogout(_: Request, res: Response): void;
|
4
|
+
export declare function oauthCallback(req: Request, res: Response): Promise<void>;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
3
|
+
import { exchangeOAuthToken, getOAuthLoginPath, removeOAuthCookies, saveOAuthTokensInCookies } from '../components/oauth';
|
4
|
+
export function oauthLogin(req, res) {
|
5
|
+
res.redirect(getOAuthLoginPath(req));
|
6
|
+
}
|
7
|
+
export function oauthLogout(_, res) {
|
8
|
+
removeOAuthCookies(res);
|
9
|
+
res.redirect('/');
|
10
|
+
}
|
11
|
+
export function oauthCallback(_x, _x2) {
|
12
|
+
return _oauthCallback.apply(this, arguments);
|
13
|
+
}
|
14
|
+
function _oauthCallback() {
|
15
|
+
_oauthCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, res) {
|
16
|
+
var code, tokens, message;
|
17
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
19
|
+
case 0:
|
20
|
+
code = req.query.code;
|
21
|
+
if (code) {
|
22
|
+
_context.next = 3;
|
23
|
+
break;
|
24
|
+
}
|
25
|
+
throw new Error('Authorization code is not specified');
|
26
|
+
case 3:
|
27
|
+
_context.prev = 3;
|
28
|
+
_context.next = 6;
|
29
|
+
return exchangeOAuthToken(req, code);
|
30
|
+
case 6:
|
31
|
+
tokens = _context.sent;
|
32
|
+
saveOAuthTokensInCookies(res, tokens);
|
33
|
+
res.redirect('/');
|
34
|
+
_context.next = 16;
|
35
|
+
break;
|
36
|
+
case 11:
|
37
|
+
_context.prev = 11;
|
38
|
+
_context.t0 = _context["catch"](3);
|
39
|
+
req.ctx.logError('exchange token error', _context.t0);
|
40
|
+
message = _context.t0 instanceof Error ? _context.t0.message : 'Unknown error';
|
41
|
+
res.status(500).send(message);
|
42
|
+
case 16:
|
43
|
+
case "end":
|
44
|
+
return _context.stop();
|
45
|
+
}
|
46
|
+
}, _callee, null, [[3, 11]]);
|
47
|
+
}));
|
48
|
+
return _oauthCallback.apply(this, arguments);
|
49
|
+
}
|
50
|
+
// #sourceMappingURL=oauth-login.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["exchangeOAuthToken","getOAuthLoginPath","removeOAuthCookies","saveOAuthTokensInCookies","oauthLogin","req","res","redirect","oauthLogout","_","oauthCallback","_x","_x2","_oauthCallback","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee","code","tokens","message","wrap","_callee$","_context","prev","next","query","Error","sent","t0","ctx","logError","status","send","stop"],"sources":["oauth-login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport {\n exchangeOAuthToken,\n getOAuthLoginPath,\n removeOAuthCookies,\n saveOAuthTokensInCookies,\n} from '../components/oauth';\n\nexport function oauthLogin(req: Request, res: Response) {\n res.redirect(getOAuthLoginPath(req));\n}\n\nexport function oauthLogout(_: Request, res: Response) {\n removeOAuthCookies(res);\n res.redirect('/');\n}\n\nexport async function oauthCallback(req: Request, res: Response) {\n const {code} = req.query;\n if (!code) {\n throw new Error('Authorization code is not specified');\n }\n\n try {\n const tokens = await exchangeOAuthToken(req, code as string);\n\n saveOAuthTokensInCookies(res, tokens);\n\n res.redirect('/');\n } catch (e) {\n req.ctx.logError('exchange token error', e);\n const message = e instanceof Error ? e.message : 'Unknown error';\n res.status(500).send(message);\n }\n}\n"],"mappings":";;AACA,SACIA,kBAAkB,EAClBC,iBAAiB,EACjBC,kBAAkB,EAClBC,wBAAwB,QACrB,qBAAqB;AAE5B,OAAO,SAASC,UAAUA,CAACC,GAAY,EAAEC,GAAa,EAAE;EACpDA,GAAG,CAACC,QAAQ,CAACN,iBAAiB,CAACI,GAAG,CAAC,CAAC;AACxC;AAEA,OAAO,SAASG,WAAWA,CAACC,CAAU,EAAEH,GAAa,EAAE;EACnDJ,kBAAkB,CAACI,GAAG,CAAC;EACvBA,GAAG,CAACC,QAAQ,CAAC,GAAG,CAAC;AACrB;AAEA,gBAAsBG,aAAaA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,cAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAiBlC,SAAAF,eAAA;EAAAA,cAAA,GAAAG,iBAAA,eAAAC,mBAAA,CAAAC,IAAA,CAjBM,SAAAC,QAA6Bd,GAAY,EAAEC,GAAa;IAAA,IAAAc,IAAA,EAAAC,MAAA,EAAAC,OAAA;IAAA,OAAAL,mBAAA,CAAAM,IAAA,UAAAC,SAAAC,QAAA;MAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;QAAA;UACpDP,IAAI,GAAIf,GAAG,CAACuB,KAAK,CAAjBR,IAAI;UAAA,IACNA,IAAI;YAAAK,QAAA,CAAAE,IAAA;YAAA;UAAA;UAAA,MACC,IAAIE,KAAK,CAAC,qCAAqC,CAAC;QAAA;UAAAJ,QAAA,CAAAC,IAAA;UAAAD,QAAA,CAAAE,IAAA;UAAA,OAIjC3B,kBAAkB,CAACK,GAAG,EAAEe,IAAc,CAAC;QAAA;UAAtDC,MAAM,GAAAI,QAAA,CAAAK,IAAA;UAEZ3B,wBAAwB,CAACG,GAAG,EAAEe,MAAM,CAAC;UAErCf,GAAG,CAACC,QAAQ,CAAC,GAAG,CAAC;UAACkB,QAAA,CAAAE,IAAA;UAAA;QAAA;UAAAF,QAAA,CAAAC,IAAA;UAAAD,QAAA,CAAAM,EAAA,GAAAN,QAAA;UAElBpB,GAAG,CAAC2B,GAAG,CAACC,QAAQ,CAAC,sBAAsB,EAAAR,QAAA,CAAAM,EAAG,CAAC;UACrCT,OAAO,GAAGG,QAAA,CAAAM,EAAA,YAAaF,KAAK,GAAGJ,QAAA,CAAAM,EAAA,CAAET,OAAO,GAAG,eAAe;UAChEhB,GAAG,CAAC4B,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAACb,OAAO,CAAC;QAAC;QAAA;UAAA,OAAAG,QAAA,CAAAW,IAAA;MAAA;IAAA,GAAAjB,OAAA;EAAA,CAErC;EAAA,OAAAN,cAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA"}
|
@@ -1,10 +1,14 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
1
2
|
var _nodekit$config$adjus, _nodekit$config3;
|
2
3
|
import path from 'path';
|
3
4
|
import { NodeKit } from '@gravity-ui/nodekit';
|
4
5
|
import { ExpressKit } from '@gravity-ui/expresskit';
|
5
6
|
import { configureApp } from './configure-app';
|
6
|
-
import {
|
7
|
+
import { createYTAuthorizationResolver } from './middlewares/yt-auth';
|
7
8
|
import routes from './routes';
|
9
|
+
import { createOAuthAuthorizationResolver } from './middlewares/oauth';
|
10
|
+
import { createAuthMiddleware } from './middlewares/authorization';
|
11
|
+
import { authorizationResolver } from './utils/authorization';
|
8
12
|
var nodekit = new NodeKit({
|
9
13
|
configsPath: path.resolve(__dirname, './configs')
|
10
14
|
});
|
@@ -26,7 +30,8 @@ if (ytAuthCluster) {
|
|
26
30
|
if (appAuthHandler) {
|
27
31
|
nodekit.ctx.fail(new Error('"appAuthHandler" option will be ignored cause "ytAuthCluster" option is provided.'));
|
28
32
|
}
|
29
|
-
nodekit.config.
|
33
|
+
nodekit.config.appBeforeAuthMiddleware = [].concat(_toConsumableArray(nodekit.config.appBeforeAuthMiddleware || []), [authorizationResolver(createOAuthAuthorizationResolver()), authorizationResolver(createYTAuthorizationResolver())]);
|
34
|
+
nodekit.config.appAuthHandler = createAuthMiddleware(ytAuthCluster);
|
30
35
|
}
|
31
36
|
(_nodekit$config$adjus = (_nodekit$config3 = nodekit.config).adjustAppConfig) === null || _nodekit$config$adjus === void 0 || _nodekit$config$adjus.call(_nodekit$config3, nodekit);
|
32
37
|
var app = new ExpressKit(nodekit, routes);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["path","NodeKit","ExpressKit","configureApp","
|
1
|
+
{"version":3,"names":["path","NodeKit","ExpressKit","configureApp","createYTAuthorizationResolver","routes","createOAuthAuthorizationResolver","createAuthMiddleware","authorizationResolver","nodekit","configsPath","resolve","__dirname","_nodekit$config","config","appName","appEnv","appInstallation","appDevMode","ctx","log","_nodekit$config2","ytAuthCluster","appAuthHandler","fail","Error","appBeforeAuthMiddleware","concat","_toConsumableArray","_nodekit$config$adjus","_nodekit$config3","adjustAppConfig","call","app","require","main","module","run"],"sources":["index.ts"],"sourcesContent":["import path from 'path';\nimport _reduce from 'lodash/reduce';\nimport {NodeKit} from '@gravity-ui/nodekit';\nimport {ExpressKit} from '@gravity-ui/expresskit';\n\nimport {configureApp} from './configure-app';\n\nimport {createYTAuthorizationResolver} from './middlewares/yt-auth';\nimport routes from './routes';\nimport {createOAuthAuthorizationResolver} from './middlewares/oauth';\nimport {createAuthMiddleware} from './middlewares/authorization';\nimport {authorizationResolver} from './utils/authorization';\n\nconst nodekit = new NodeKit({configsPath: path.resolve(__dirname, './configs')});\n\nconst {appName, appEnv, appInstallation, appDevMode} = nodekit.config;\nnodekit.ctx.log('AppConfig details', {\n appName,\n appEnv,\n appInstallation,\n appDevMode,\n});\n\nconst {ytAuthCluster, appAuthHandler} = nodekit.config;\n\nif (ytAuthCluster) {\n if (appAuthHandler) {\n nodekit.ctx.fail(\n new Error(\n '\"appAuthHandler\" option will be ignored cause \"ytAuthCluster\" option is provided.',\n ),\n );\n }\n\n nodekit.config.appBeforeAuthMiddleware = [\n ...(nodekit.config.appBeforeAuthMiddleware || []),\n authorizationResolver(createOAuthAuthorizationResolver()),\n authorizationResolver(createYTAuthorizationResolver()),\n ];\n nodekit.config.appAuthHandler = createAuthMiddleware(ytAuthCluster);\n}\n\nnodekit.config.adjustAppConfig?.(nodekit);\n\nconst app = new ExpressKit(nodekit, routes);\nconfigureApp(app);\n\nif (require.main === module) {\n app.run();\n}\n\nexport default app;\n"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAAQC,OAAO,QAAO,qBAAqB;AAC3C,SAAQC,UAAU,QAAO,wBAAwB;AAEjD,SAAQC,YAAY,QAAO,iBAAiB;AAE5C,SAAQC,6BAA6B,QAAO,uBAAuB;AACnE,OAAOC,MAAM,MAAM,UAAU;AAC7B,SAAQC,gCAAgC,QAAO,qBAAqB;AACpE,SAAQC,oBAAoB,QAAO,6BAA6B;AAChE,SAAQC,qBAAqB,QAAO,uBAAuB;AAE3D,IAAMC,OAAO,GAAG,IAAIR,OAAO,CAAC;EAACS,WAAW,EAAEV,IAAI,CAACW,OAAO,CAACC,SAAS,EAAE,WAAW;AAAC,CAAC,CAAC;AAEhF,IAAAC,eAAA,GAAuDJ,OAAO,CAACK,MAAM;EAA9DC,OAAO,GAAAF,eAAA,CAAPE,OAAO;EAAEC,MAAM,GAAAH,eAAA,CAANG,M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