@hellocoop/express 1.8.0 → 1.8.2
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.d.ts +17 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +75 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +2 -5
- package/dist/server.js +3 -2
- package/package.json +4 -3
- package/dist/handlers/auth.d.ts +0 -10
- package/dist/handlers/auth.d.ts.map +0 -1
- package/dist/handlers/auth.js +0 -46
- package/dist/handlers/callback.d.ts +0 -4
- package/dist/handlers/callback.d.ts.map +0 -1
- package/dist/handlers/callback.js +0 -127
- package/dist/handlers/config.d.ts +0 -31
- package/dist/handlers/config.d.ts.map +0 -1
- package/dist/handlers/config.js +0 -21
- package/dist/handlers/login.d.ts +0 -4
- package/dist/handlers/login.d.ts.map +0 -1
- package/dist/handlers/login.js +0 -66
- package/dist/handlers/logout.d.ts +0 -4
- package/dist/handlers/logout.d.ts.map +0 -1
- package/dist/handlers/logout.js +0 -13
- package/dist/handlers/router.d.ts +0 -4
- package/dist/handlers/router.d.ts.map +0 -1
- package/dist/handlers/router.js +0 -57
- package/dist/handlers/wildcard.d.ts +0 -4
- package/dist/handlers/wildcard.d.ts.map +0 -1
- package/dist/handlers/wildcard.js +0 -7
- package/dist/lib/auth.d.ts +0 -7
- package/dist/lib/auth.d.ts.map +0 -1
- package/dist/lib/auth.js +0 -58
- package/dist/lib/config.d.ts +0 -41
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -98
- package/dist/lib/oidc.d.ts +0 -11
- package/dist/lib/oidc.d.ts.map +0 -1
- package/dist/lib/oidc.js +0 -54
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { Auth } from '@hellocoop/types';
|
|
3
|
+
import { Config } from '@hellocoop/router';
|
|
4
|
+
export type HelloConfig = Config;
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Express {
|
|
7
|
+
interface Request {
|
|
8
|
+
auth?: Auth;
|
|
9
|
+
getAuth(): Promise<Auth>;
|
|
10
|
+
}
|
|
11
|
+
interface Response {
|
|
12
|
+
clearAuth(): void;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare const auth: (config: Config) => Router;
|
|
17
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAA;AAGjE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAQH,MAAM,EAET,MAAM,mBAAmB,CAAA;AAE1B,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAmChC,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE,IAAI,CAAC;YACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QACD,UAAU,QAAQ;YAChB,SAAS,IAAI,IAAI,CAAC;SACnB;KACF;CACF;AAmBH,eAAO,MAAM,IAAI,WAAsB,MAAM,KAAG,MA2B/C,CAAA"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.auth = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const cookie_1 = require("cookie");
|
|
6
|
+
const router_1 = require("@hellocoop/router");
|
|
7
|
+
const convertToHelloRequest = (req) => {
|
|
8
|
+
return {
|
|
9
|
+
headers: () => req.headers,
|
|
10
|
+
query: req.query,
|
|
11
|
+
path: req.path,
|
|
12
|
+
getAuth: () => req.auth,
|
|
13
|
+
setAuth: (auth) => { req.auth = auth; },
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const convertToHelloResponse = (res) => {
|
|
17
|
+
return {
|
|
18
|
+
clearAuth: () => {
|
|
19
|
+
const { name, value, options } = (0, router_1.clearAuthCookieParams)();
|
|
20
|
+
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
21
|
+
},
|
|
22
|
+
send: (data) => res.type('text/html').send(data),
|
|
23
|
+
json: (data) => res.json(data),
|
|
24
|
+
redirect: (url) => res.redirect(url),
|
|
25
|
+
setCookie: (name, value, options) => {
|
|
26
|
+
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
27
|
+
},
|
|
28
|
+
setHeader: (name, value) => res.setHeader(name, value),
|
|
29
|
+
status: (statusCode) => {
|
|
30
|
+
res.status(statusCode);
|
|
31
|
+
return {
|
|
32
|
+
send: (data) => res.send(data)
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
// // Express middleware for auth
|
|
38
|
+
// app.use( async (req: Request, res: Response, next: NextFunction) => {
|
|
39
|
+
// const helloReq = convertToHelloRequest(req)
|
|
40
|
+
// req.auth = await getAuthfromCookies(helloReq)
|
|
41
|
+
// next()
|
|
42
|
+
// })
|
|
43
|
+
// // Express route
|
|
44
|
+
// app.get('/api/hellocoop', async (req: Request, res: Response) => {
|
|
45
|
+
// const helloReq = convertToHelloRequest(req)
|
|
46
|
+
// const helloRes = convertToHelloResponse(res)
|
|
47
|
+
// return await router(helloReq, helloRes)
|
|
48
|
+
// })
|
|
49
|
+
// Configure plugin options if needed
|
|
50
|
+
const auth = function (config) {
|
|
51
|
+
if (!router_1.isConfigured) {
|
|
52
|
+
(0, router_1.configure)(config);
|
|
53
|
+
}
|
|
54
|
+
console.log({ isConfigured: router_1.isConfigured, configuration: router_1.configuration });
|
|
55
|
+
const r = (0, express_1.Router)();
|
|
56
|
+
r.use(async (req, res, next) => {
|
|
57
|
+
const helloReq = convertToHelloRequest(req);
|
|
58
|
+
req.getAuth = async () => {
|
|
59
|
+
req.auth = await (0, router_1.getAuthfromCookies)(helloReq);
|
|
60
|
+
return req.auth;
|
|
61
|
+
};
|
|
62
|
+
res.clearAuth = () => {
|
|
63
|
+
const { name, value, options } = (0, router_1.clearAuthCookieParams)();
|
|
64
|
+
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
65
|
+
};
|
|
66
|
+
next();
|
|
67
|
+
});
|
|
68
|
+
r.get('/api/hellocoop', async (req, res) => {
|
|
69
|
+
const helloReq = convertToHelloRequest(req);
|
|
70
|
+
const helloRes = convertToHelloResponse(res);
|
|
71
|
+
await (0, router_1.router)(helloReq, helloRes);
|
|
72
|
+
});
|
|
73
|
+
return r;
|
|
74
|
+
};
|
|
75
|
+
exports.auth = auth;
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC1C,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.helloAuth = void 0;
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "helloAuth", { enumerable: true, get: function () { return
|
|
6
|
-
exports.default =
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
Object.defineProperty(exports, "helloAuth", { enumerable: true, get: function () { return auth_1.auth; } });
|
|
6
|
+
exports.default = auth_1.auth;
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAKzD,eAAO,MAAM,QAAQ,WAAqB,MAAM,WACxB,OAAO,OAAO,QAAQ,QAAQ,YAAY,kBAOjE,CAAA;AAED,eAAO,MAAM,YAAY,QAAgB,OAAO,OAAO,QAAQ,QAAQ,YAAY,kBAMlF,CAAA;AAED,eAAO,MAAM,OAAO,QAAgB,OAAO,OAAO,QAAQ,QAAQ,YAAY,kBAG7E,CAAA"}
|
package/dist/middleware.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.setAuth = exports.unauthorized = exports.redirect = void 0;
|
|
7
|
-
const
|
|
4
|
+
const router_1 = require("@hellocoop/router");
|
|
8
5
|
const redirect = function (target) {
|
|
9
6
|
return async (req, res, next) => {
|
|
10
7
|
const auth = await req.getAuth();
|
|
@@ -20,7 +17,7 @@ const unauthorized = async (req, res, next) => {
|
|
|
20
17
|
if (auth.isLoggedIn)
|
|
21
18
|
next();
|
|
22
19
|
else
|
|
23
|
-
res.setHeader('WWW-Authenticate', `Hello ${
|
|
20
|
+
res.setHeader('WWW-Authenticate', `Hello ${router_1.configuration.clientId}`).status(401).send();
|
|
24
21
|
};
|
|
25
22
|
exports.unauthorized = unauthorized;
|
|
26
23
|
const setAuth = async (req, res, next) => {
|
package/dist/server.js
CHANGED
|
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
// test server
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const index_1 =
|
|
8
|
+
const index_1 = require("./index");
|
|
9
9
|
const middleware_1 = require("./middleware");
|
|
10
|
+
const config = require('../hello.config.js');
|
|
10
11
|
const app = (0, express_1.default)();
|
|
11
12
|
const port = 8080; // default port to listen
|
|
12
|
-
app.use((0, index_1.
|
|
13
|
+
app.use((0, index_1.helloAuth)(config));
|
|
13
14
|
app.get("/", async (req, res) => {
|
|
14
15
|
res.json(await req.getAuth());
|
|
15
16
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellocoop/express",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Express SDK for Hellō https://hello.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"express": "^4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
+
"@hellocoop/types": "*",
|
|
47
48
|
"@tsconfig/node18": "^18.2.2",
|
|
48
49
|
"@types/cookie": "^0.5.2",
|
|
49
50
|
"@types/express": "^4.17.20",
|
|
@@ -55,8 +56,8 @@
|
|
|
55
56
|
"node": ">=18"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@hellocoop/core": "
|
|
59
|
-
"@hellocoop/
|
|
59
|
+
"@hellocoop/core": "*",
|
|
60
|
+
"@hellocoop/constants": "*",
|
|
60
61
|
"cookie": "^0.5.0",
|
|
61
62
|
"cors": "^2.8.5",
|
|
62
63
|
"dotenv": "^16.3.1"
|
package/dist/handlers/auth.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import { Auth, Claims } from '@hellocoop/types';
|
|
3
|
-
export type AuthUpdates = Claims & {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
};
|
|
6
|
-
export declare const handleAuth: (req: Request, res: Response) => Promise<void>;
|
|
7
|
-
export declare const clearAuth: (res: Response) => Promise<void>;
|
|
8
|
-
export declare const setAuthMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
9
|
-
export declare const updateAuth: (req: Request, res: Response, authUpdates: AuthUpdates) => Promise<Auth | null>;
|
|
10
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/handlers/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIzD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAO/C,MAAM,MAAM,WAAW,GACnB,MAAM,GAAG;IACL,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAEL,eAAO,MAAM,UAAU,QAAwB,OAAO,OAAO,QAAQ,kBAKpE,CAAA;AAED,eAAO,MAAM,SAAS,QAAyB,QAAQ,kBAEtD,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAyB,OAAO,OAAO,QAAQ,QAAQ,YAAY,kBAYhG,CAAA;AAED,eAAO,MAAM,UAAU,QAAyB,OAAO,OAAO,QAAQ,eAAe,WAAW,KACtF,QAAQ,IAAI,GAAG,IAAI,CAc5B,CAAA"}
|
package/dist/handlers/auth.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateAuth = exports.setAuthMiddleware = exports.clearAuth = exports.handleAuth = void 0;
|
|
4
|
-
const auth_1 = require("../lib/auth");
|
|
5
|
-
const auth_2 = require("../lib/auth");
|
|
6
|
-
const handleAuth = async function (req, res) {
|
|
7
|
-
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
8
|
-
res.setHeader('Pragma', 'no-cache');
|
|
9
|
-
res.setHeader('Expires', '0');
|
|
10
|
-
res.json(await req.getAuth());
|
|
11
|
-
};
|
|
12
|
-
exports.handleAuth = handleAuth;
|
|
13
|
-
const clearAuth = async function (res) {
|
|
14
|
-
(0, auth_1.clearAuthCookie)(res);
|
|
15
|
-
};
|
|
16
|
-
exports.clearAuth = clearAuth;
|
|
17
|
-
const setAuthMiddleware = async function (req, res, next) {
|
|
18
|
-
let auth = undefined;
|
|
19
|
-
req.getAuth = async () => {
|
|
20
|
-
if (req.auth)
|
|
21
|
-
return req.auth;
|
|
22
|
-
req.auth = await (0, auth_1.getAuthfromCookies)(req, res) || auth_2.NotLoggedIn;
|
|
23
|
-
return req.auth;
|
|
24
|
-
};
|
|
25
|
-
res.clearAuth = async () => {
|
|
26
|
-
await (0, exports.clearAuth)(res);
|
|
27
|
-
};
|
|
28
|
-
next();
|
|
29
|
-
};
|
|
30
|
-
exports.setAuthMiddleware = setAuthMiddleware;
|
|
31
|
-
const updateAuth = async function (req, res, authUpdates) {
|
|
32
|
-
const auth = await (0, auth_1.getAuthfromCookies)(req, res);
|
|
33
|
-
if (!auth.isLoggedIn)
|
|
34
|
-
return auth;
|
|
35
|
-
const newAuth = {
|
|
36
|
-
...auth,
|
|
37
|
-
...authUpdates,
|
|
38
|
-
sub: auth.sub,
|
|
39
|
-
iat: auth.iat
|
|
40
|
-
};
|
|
41
|
-
const success = await (0, auth_1.saveAuthCookie)(res, newAuth);
|
|
42
|
-
if (success)
|
|
43
|
-
return newAuth;
|
|
44
|
-
return null;
|
|
45
|
-
};
|
|
46
|
-
exports.updateAuth = updateAuth;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/handlers/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AA8B3C,QAAA,MAAM,cAAc,QAAe,OAAO,OAAO,QAAQ,uDAyHxD,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const config_1 = __importDefault(require("../lib/config"));
|
|
7
|
-
const oidc_1 = require("../lib/oidc");
|
|
8
|
-
const core_1 = require("@hellocoop/core");
|
|
9
|
-
const auth_1 = require("../lib/auth");
|
|
10
|
-
const sendErrorPage = (error, target_uri, req, res) => {
|
|
11
|
-
if (config_1.default.routes.error) {
|
|
12
|
-
const url = new URL(config_1.default.routes.error);
|
|
13
|
-
for (const key in error) {
|
|
14
|
-
if (key.startsWith('error')) {
|
|
15
|
-
// Append each error query parameter to the URL
|
|
16
|
-
url.searchParams.append(key, error[key]);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return res.redirect(url.toString());
|
|
20
|
-
}
|
|
21
|
-
const params = {
|
|
22
|
-
error: error.error,
|
|
23
|
-
error_description: error.error_description,
|
|
24
|
-
error_uri: error.error_uri,
|
|
25
|
-
target_uri
|
|
26
|
-
};
|
|
27
|
-
const page = (0, core_1.errorPage)(params);
|
|
28
|
-
res.end(page);
|
|
29
|
-
};
|
|
30
|
-
const handleCallback = async (req, res) => {
|
|
31
|
-
var _a;
|
|
32
|
-
const { code, error, same_site, wildcard_domain, app_name, } = req.query;
|
|
33
|
-
if (!same_site) // we need to bounce so we get cookies
|
|
34
|
-
return res.send((0, core_1.sameSiteCallback)());
|
|
35
|
-
const oidcState = await (0, oidc_1.getOidc)(req, res);
|
|
36
|
-
if (!oidcState)
|
|
37
|
-
return res.status(400).end('OpenID Connect cookie lost');
|
|
38
|
-
const { code_verifier, nonce, redirect_uri, } = oidcState;
|
|
39
|
-
let { target_uri = '/' } = oidcState;
|
|
40
|
-
if (error)
|
|
41
|
-
return sendErrorPage(req.query, target_uri, req, res);
|
|
42
|
-
if (!code)
|
|
43
|
-
return res.status(400).end('Missing code parameter');
|
|
44
|
-
if (Array.isArray(code))
|
|
45
|
-
return res.status(400).end('Received more than one code.');
|
|
46
|
-
if (!code_verifier) {
|
|
47
|
-
res.status(400).end('Missing code_verifier from session');
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
(0, oidc_1.clearOidcCookie)(res); // clear cookie so we don't try to use code again
|
|
52
|
-
const token = await (0, core_1.fetchToken)({
|
|
53
|
-
code: code.toString(),
|
|
54
|
-
wallet: config_1.default.helloWallet,
|
|
55
|
-
code_verifier,
|
|
56
|
-
redirect_uri,
|
|
57
|
-
client_id: config_1.default.clientId
|
|
58
|
-
});
|
|
59
|
-
const { payload } = (0, core_1.parseToken)(token);
|
|
60
|
-
if (payload.aud != config_1.default.clientId) {
|
|
61
|
-
return res.status(400).end('Wrong ID token audience.');
|
|
62
|
-
}
|
|
63
|
-
if (payload.nonce != nonce) {
|
|
64
|
-
return res.status(400).end('Wrong nonce in ID token.');
|
|
65
|
-
}
|
|
66
|
-
const currentTimeInt = Math.floor(Date.now() / 1000);
|
|
67
|
-
if (payload.exp < currentTimeInt) {
|
|
68
|
-
return res.status(400).end('The ID token has expired.');
|
|
69
|
-
}
|
|
70
|
-
if (payload.iat > currentTimeInt + 5) { // 5 seconds of clock skew
|
|
71
|
-
return res.status(400).end('The ID token is not yet valid.');
|
|
72
|
-
}
|
|
73
|
-
let auth = {
|
|
74
|
-
isLoggedIn: true,
|
|
75
|
-
sub: payload.sub,
|
|
76
|
-
iat: payload.iat
|
|
77
|
-
};
|
|
78
|
-
// hack TypeScript
|
|
79
|
-
const claims = payload;
|
|
80
|
-
payload.scope.forEach((scope) => {
|
|
81
|
-
const claim = claims[scope];
|
|
82
|
-
if (claim)
|
|
83
|
-
auth[scope] = claim;
|
|
84
|
-
});
|
|
85
|
-
if ((_a = config_1.default.callbacks) === null || _a === void 0 ? void 0 : _a.loggedIn) {
|
|
86
|
-
try {
|
|
87
|
-
const cb = await config_1.default.callbacks.loggedIn({ token, payload, req, res });
|
|
88
|
-
if (cb === null || cb === void 0 ? void 0 : cb.accessDenied) {
|
|
89
|
-
auth = auth_1.NotLoggedIn;
|
|
90
|
-
// TODO? set target_uri to not logged in setting?
|
|
91
|
-
}
|
|
92
|
-
else if (cb === null || cb === void 0 ? void 0 : cb.updatedAuth) {
|
|
93
|
-
auth = {
|
|
94
|
-
...cb.updatedAuth,
|
|
95
|
-
isLoggedIn: true,
|
|
96
|
-
sub: payload.sub,
|
|
97
|
-
iat: payload.iat
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
target_uri = (cb === null || cb === void 0 ? void 0 : cb.target_uri) || target_uri;
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
103
|
-
console.error(new Error('callback faulted'));
|
|
104
|
-
console.error(e);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (wildcard_domain) {
|
|
108
|
-
// the redirect_uri is not registered at Hellō - prompt to add
|
|
109
|
-
const appName = app_name || 'Your App';
|
|
110
|
-
const queryString = new URLSearchParams({
|
|
111
|
-
uri: wildcard_domain,
|
|
112
|
-
appName,
|
|
113
|
-
redirectURI: redirect_uri,
|
|
114
|
-
targetURI: target_uri,
|
|
115
|
-
wildcard_console: 'true'
|
|
116
|
-
}).toString();
|
|
117
|
-
target_uri = config_1.default.apiRoute + '?' + queryString;
|
|
118
|
-
}
|
|
119
|
-
await (0, auth_1.saveAuthCookie)(res, auth);
|
|
120
|
-
res.json({ target_uri });
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
(0, oidc_1.clearOidcCookie)(res);
|
|
124
|
-
return res.status(500).end(error.message);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
exports.default = handleCallback;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Router, Request, Response } from 'express';
|
|
2
|
-
import { Claims, Scope, ProviderHint } from '@hellocoop/types';
|
|
3
|
-
export { Claims, Scope };
|
|
4
|
-
export type LoggedInParams = {
|
|
5
|
-
token: string;
|
|
6
|
-
payload: Claims;
|
|
7
|
-
req: Request;
|
|
8
|
-
res: Response;
|
|
9
|
-
};
|
|
10
|
-
export type LoggedInResponse = {
|
|
11
|
-
accessDenied?: boolean;
|
|
12
|
-
target_uri?: string;
|
|
13
|
-
updatedAuth?: {
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type Config = {
|
|
18
|
-
client_id?: string;
|
|
19
|
-
scope?: Scope[];
|
|
20
|
-
provider_hint?: ProviderHint[];
|
|
21
|
-
callbacks?: {
|
|
22
|
-
loggedIn?: (params: LoggedInParams) => Promise<LoggedInResponse>;
|
|
23
|
-
};
|
|
24
|
-
routes?: {
|
|
25
|
-
loggedIn?: string;
|
|
26
|
-
loggedOut?: string;
|
|
27
|
-
error?: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export declare const auth: (config: Config) => Router;
|
|
31
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/handlers/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAInD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE9D,OAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAEzB,MAAM,MAAM,cAAc,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAA;CAChB,CAAA;AAGD,MAAM,MAAM,gBAAgB,GAAG;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAA;CACrC,CAAA;AAGD,MAAM,MAAM,MAAM,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,SAAS,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;KACnE,CAAC;IACF,MAAM,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;CACJ,CAAA;AAED,eAAO,MAAM,IAAI,WAAsB,MAAM,KAAG,MAQ/C,CAAA"}
|
package/dist/handlers/config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.auth = void 0;
|
|
7
|
-
const express_1 = require("express");
|
|
8
|
-
const cors_1 = __importDefault(require("cors"));
|
|
9
|
-
const config_1 = require("../lib/config");
|
|
10
|
-
const router_1 = __importDefault(require("./router"));
|
|
11
|
-
const auth_1 = require("./auth");
|
|
12
|
-
const auth = function (config) {
|
|
13
|
-
if (!config_1.isConfigured) {
|
|
14
|
-
(0, config_1.configure)(config);
|
|
15
|
-
}
|
|
16
|
-
const r = (0, express_1.Router)();
|
|
17
|
-
r.use(auth_1.setAuthMiddleware);
|
|
18
|
-
r.get('/api/hellocoop', (0, cors_1.default)(), router_1.default);
|
|
19
|
-
return r;
|
|
20
|
-
};
|
|
21
|
-
exports.auth = auth;
|
package/dist/handlers/login.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/handlers/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAU3C,QAAA,MAAM,WAAW,QAAe,OAAO,OAAO,QAAQ,4DAuDrD,CAAA;AAED,eAAe,WAAW,CAAA"}
|
package/dist/handlers/login.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const core_1 = require("@hellocoop/core");
|
|
7
|
-
const config_1 = __importDefault(require("../lib/config"));
|
|
8
|
-
const oidc_1 = require("../lib/oidc");
|
|
9
|
-
var redirectURIs = {};
|
|
10
|
-
// var callCount = 0 // DEBUG
|
|
11
|
-
const handleLogin = async (req, res) => {
|
|
12
|
-
var _a;
|
|
13
|
-
const { provider_hint: providerParam, scope: scopeParam, target_uri, redirect_uri } = req.query;
|
|
14
|
-
if (!config_1.default.clientId) {
|
|
15
|
-
res.status(500).end('Missing HELLO_CLIENT_ID configuration');
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
// callCount++
|
|
19
|
-
// console.log('login called:',callCount)
|
|
20
|
-
let redirectURI = config_1.default.redirectURI;
|
|
21
|
-
let host = (_a = req.headers) === null || _a === void 0 ? void 0 : _a.host;
|
|
22
|
-
if (!redirectURI) {
|
|
23
|
-
if (redirectURIs[host]) {
|
|
24
|
-
redirectURI = redirectURIs[host];
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
if (redirect_uri) {
|
|
28
|
-
const redirectUriString = (Array.isArray(redirect_uri) ? redirect_uri[0] : redirect_uri);
|
|
29
|
-
const redirectHost = (new URL(redirectUriString)).host;
|
|
30
|
-
if (redirectHost != host) {
|
|
31
|
-
// TBd -- this might happen if we are behind a proxy where our host and the browser host are different -- look at X-headerrs
|
|
32
|
-
const err = `host from redirect_uri=${redirectHost}, expected ${host}`;
|
|
33
|
-
console.error(err);
|
|
34
|
-
return res.status(500).end(err);
|
|
35
|
-
}
|
|
36
|
-
redirectURIs[host] = redirectURI = redirect_uri;
|
|
37
|
-
console.log(`Hellō: RedirectURI for ${host} => ${redirectURI}`);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
console.log('Hellō: Discovering API RedirectURI route ...');
|
|
41
|
-
return res.end((0, core_1.redirectURIBounce)());
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// parse out param strings
|
|
46
|
-
const targetURIstring = (Array.isArray(providerParam) ? providerParam[0] : providerParam);
|
|
47
|
-
const provider_hint = targetURIstring === null || targetURIstring === void 0 ? void 0 : targetURIstring.split(' ').map((s) => s.trim());
|
|
48
|
-
const scopeString = (Array.isArray(scopeParam) ? scopeParam[0] : scopeParam);
|
|
49
|
-
const scope = scopeString === null || scopeString === void 0 ? void 0 : scopeString.split(' ').map((s) => s.trim());
|
|
50
|
-
const request = {
|
|
51
|
-
redirect_uri: redirectURI,
|
|
52
|
-
client_id: config_1.default.clientId,
|
|
53
|
-
wallet: config_1.default.helloWallet,
|
|
54
|
-
scope,
|
|
55
|
-
provider_hint
|
|
56
|
-
};
|
|
57
|
-
const { url, nonce, code_verifier } = await (0, core_1.createAuthRequest)(request);
|
|
58
|
-
await (0, oidc_1.saveOidc)(req, res, {
|
|
59
|
-
nonce,
|
|
60
|
-
code_verifier,
|
|
61
|
-
redirect_uri: redirectURI,
|
|
62
|
-
target_uri: (Array.isArray(target_uri) ? target_uri[0] : target_uri) || config_1.default.routes.loggedIn
|
|
63
|
-
});
|
|
64
|
-
res.redirect(url);
|
|
65
|
-
};
|
|
66
|
-
exports.default = handleLogin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/handlers/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAI3C,QAAA,MAAM,YAAY,QAAe,OAAO,OAAO,QAAQ,kBAItD,CAAA;AAED,eAAe,YAAY,CAAA"}
|
package/dist/handlers/logout.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const auth_1 = require("../lib/auth");
|
|
7
|
-
const config_1 = __importDefault(require("../lib/config"));
|
|
8
|
-
const handleLogout = async (req, res) => {
|
|
9
|
-
const { target_uri } = req.query;
|
|
10
|
-
await (0, auth_1.clearAuthCookie)(res);
|
|
11
|
-
res.redirect(target_uri || config_1.default.routes.loggedOut);
|
|
12
|
-
};
|
|
13
|
-
exports.default = handleLogout;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/handlers/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AA6B3C,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,wGAsC1C,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/handlers/router.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const config_1 = __importDefault(require("../lib/config"));
|
|
7
|
-
const callback_1 = __importDefault(require("./callback"));
|
|
8
|
-
const login_1 = __importDefault(require("./login"));
|
|
9
|
-
const logout_1 = __importDefault(require("./logout"));
|
|
10
|
-
const wildcard_1 = __importDefault(require("./wildcard"));
|
|
11
|
-
const auth_1 = require("./auth");
|
|
12
|
-
const auth_2 = require("../lib/auth");
|
|
13
|
-
// const translateHandlerErrors = (handler: Router): Router =>
|
|
14
|
-
// async (req: Request, res: Response, next: NextFunction) => {
|
|
15
|
-
// try {
|
|
16
|
-
// await handler(req, res, next)
|
|
17
|
-
// next()
|
|
18
|
-
// } catch (error: any) {
|
|
19
|
-
// console.error(error)
|
|
20
|
-
// res.status(error?.status || 500).end(error.message)
|
|
21
|
-
// }
|
|
22
|
-
// }
|
|
23
|
-
// // console.log('config\n',JSON.stringify(config,null,4))
|
|
24
|
-
// const router = translateHandlerErrors((req: Request, res: Response, next: NextFunction ) => {
|
|
25
|
-
// const { query } = req
|
|
26
|
-
// // console.log({query})
|
|
27
|
-
const router = (req, res) => {
|
|
28
|
-
const { query } = req;
|
|
29
|
-
if (query.auth || query.getAuth) { // get auth object
|
|
30
|
-
if (config_1.default.error) {
|
|
31
|
-
return res.end(auth_2.NotLoggedIn);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return (0, auth_1.handleAuth)(req, res);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (config_1.default.error) // not able to process requests
|
|
38
|
-
return res.status(500).end('Missing configuration:\n' + JSON.stringify(config_1.default.error, null, 4));
|
|
39
|
-
if (query.login) { // start login flow, redirect to Hellō
|
|
40
|
-
return (0, login_1.default)(req, res);
|
|
41
|
-
}
|
|
42
|
-
if (query.code || query.error) { // authorization response
|
|
43
|
-
return (0, callback_1.default)(req, res);
|
|
44
|
-
}
|
|
45
|
-
if (query.logout) { // logout user
|
|
46
|
-
return (0, logout_1.default)(req, res);
|
|
47
|
-
}
|
|
48
|
-
if (query.wildcard_console) {
|
|
49
|
-
return (0, wildcard_1.default)(req, res);
|
|
50
|
-
}
|
|
51
|
-
if (query.iss) { // IdP (Hellō) initiated login
|
|
52
|
-
// https://openid.net/specs/openid-connect-core-1_0.html#ThirdPartyInitiatedLogin
|
|
53
|
-
throw new Error('unimplemented');
|
|
54
|
-
}
|
|
55
|
-
res.status(500).end('Invalid hellocoop call:\n' + JSON.stringify(query, null, 4));
|
|
56
|
-
};
|
|
57
|
-
exports.default = router;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wildcard.d.ts","sourceRoot":"","sources":["../../src/handlers/wildcard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAG3C,QAAA,MAAM,cAAc,QAAe,OAAO,OAAO,QAAQ,kBAExD,CAAA;AACD,eAAe,cAAc,CAAA"}
|
package/dist/lib/auth.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Auth } from '@hellocoop/types';
|
|
2
|
-
import { Request, Response } from 'express';
|
|
3
|
-
export declare const saveAuthCookie: (res: Response, auth: Auth) => Promise<boolean>;
|
|
4
|
-
export declare const clearAuthCookie: (res: Response) => Promise<void>;
|
|
5
|
-
export declare const getAuthfromCookies: (req: Request, res: Response) => Promise<Auth>;
|
|
6
|
-
export declare const NotLoggedIn: Auth;
|
|
7
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/dist/lib/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,cAAc,QAAgB,QAAQ,QAAQ,IAAI,KAAG,QAAQ,OAAO,CAgBhF,CAAA;AAED,eAAO,MAAM,eAAe,QAAgB,QAAQ,kBAKnD,CAAA;AAGD,eAAO,MAAM,kBAAkB,QAChB,OAAO,OAAO,QAAQ,KAC3B,QAAQ,IAAI,CAoBrB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,IAA2B,CAAA"}
|
package/dist/lib/auth.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NotLoggedIn = exports.getAuthfromCookies = exports.clearAuthCookie = exports.saveAuthCookie = void 0;
|
|
7
|
-
const core_1 = require("@hellocoop/core");
|
|
8
|
-
const config_1 = __importDefault(require("./config"));
|
|
9
|
-
const cookie_1 = require("cookie");
|
|
10
|
-
const oidc_1 = require("./oidc");
|
|
11
|
-
const { cookies: { authName, oidcName } } = config_1.default;
|
|
12
|
-
const saveAuthCookie = async (res, auth) => {
|
|
13
|
-
try {
|
|
14
|
-
const encCookie = await (0, core_1.encryptObj)(auth, config_1.default.secret);
|
|
15
|
-
if (!encCookie)
|
|
16
|
-
return false;
|
|
17
|
-
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(authName, encCookie, {
|
|
18
|
-
httpOnly: true,
|
|
19
|
-
secure: config_1.default.production,
|
|
20
|
-
sameSite: 'lax',
|
|
21
|
-
path: '/' // let any server side route call getAuth
|
|
22
|
-
}));
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
console.error(e);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
exports.saveAuthCookie = saveAuthCookie;
|
|
31
|
-
const clearAuthCookie = async (res) => {
|
|
32
|
-
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(authName, '', {
|
|
33
|
-
expires: new Date(0),
|
|
34
|
-
path: '/', // Specify the path
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
37
|
-
exports.clearAuthCookie = clearAuthCookie;
|
|
38
|
-
const getAuthfromCookies = async function (req, res) {
|
|
39
|
-
const cookies = (0, cookie_1.parse)(req.headers.cookie || '');
|
|
40
|
-
if (cookies[oidcName]) // clear OIDC cookie if still there
|
|
41
|
-
(0, oidc_1.clearOidcCookie)(res);
|
|
42
|
-
const authCookie = cookies[authName];
|
|
43
|
-
if (!authCookie)
|
|
44
|
-
return exports.NotLoggedIn;
|
|
45
|
-
try {
|
|
46
|
-
const auth = await (0, core_1.decryptObj)(authCookie, config_1.default.secret);
|
|
47
|
-
if (auth) {
|
|
48
|
-
return auth;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
await (0, exports.clearAuthCookie)(res);
|
|
53
|
-
console.error(e);
|
|
54
|
-
}
|
|
55
|
-
return exports.NotLoggedIn;
|
|
56
|
-
};
|
|
57
|
-
exports.getAuthfromCookies = getAuthfromCookies;
|
|
58
|
-
exports.NotLoggedIn = { isLoggedIn: false };
|
package/dist/lib/config.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Scope } from '@hellocoop/types';
|
|
2
|
-
import { Config, LoggedInParams, LoggedInResponse } from '../handlers/config';
|
|
3
|
-
import { ProviderHint } from '@hellocoop/types';
|
|
4
|
-
export interface IConfig {
|
|
5
|
-
production: boolean;
|
|
6
|
-
error?: string[];
|
|
7
|
-
scope?: Scope[];
|
|
8
|
-
provider_hint?: ProviderHint[];
|
|
9
|
-
routes: {
|
|
10
|
-
loggedIn: string;
|
|
11
|
-
loggedOut: string;
|
|
12
|
-
error?: string;
|
|
13
|
-
};
|
|
14
|
-
cookies: {
|
|
15
|
-
authName: string;
|
|
16
|
-
oidcName: string;
|
|
17
|
-
};
|
|
18
|
-
callbacks: {
|
|
19
|
-
loggedIn?: (params: LoggedInParams) => Promise<LoggedInResponse>;
|
|
20
|
-
};
|
|
21
|
-
apiRoute: string;
|
|
22
|
-
authApiRoute: string;
|
|
23
|
-
loginApiRoute: string;
|
|
24
|
-
logoutApiRoute: string;
|
|
25
|
-
clientId: string;
|
|
26
|
-
host: string | undefined;
|
|
27
|
-
redirectURI: string | undefined;
|
|
28
|
-
helloDomain: string;
|
|
29
|
-
helloWallet: string;
|
|
30
|
-
secret?: string;
|
|
31
|
-
}
|
|
32
|
-
declare const _configuration: IConfig;
|
|
33
|
-
export declare let isConfigured: boolean;
|
|
34
|
-
export declare const configure: (config: Config) => void;
|
|
35
|
-
export declare const getConfig: () => Promise<IConfig>;
|
|
36
|
-
export declare const getLoginApiRoute: () => string;
|
|
37
|
-
export declare const getLogoutApiRoute: () => string;
|
|
38
|
-
export declare const getAuthApiRoute: () => string;
|
|
39
|
-
export declare const getApiRoute: () => string;
|
|
40
|
-
export default _configuration;
|
|
41
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/lib/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAM/C,MAAM,WAAW,OAAO;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,MAAM,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAA;KACjB,CAAC;IACF,OAAO,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,SAAS,EAAE;QACP,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;KACnE,CAAC;IAEF,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IAEvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAE;IAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAEhC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAKD,QAAA,MAAM,cAAc,EAAE,OA+BrB,CAAA;AAED,eAAO,IAAI,YAAY,EAAE,OAAe,CAAA;AAKxC,eAAO,MAAM,SAAS,WAAsB,MAAM,SAuCjD,CAAA;AAED,eAAO,MAAM,SAAS,QAAe,QAAQ,OAAO,CAOnD,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAM,MAA+C,CAAA;AAClF,eAAO,MAAM,iBAAiB,QAAM,MAAgD,CAAA;AACpF,eAAO,MAAM,eAAe,QAAM,MAA8C,CAAA;AAChF,eAAO,MAAM,WAAW,QAAM,MAA0C,CAAA;AAExE,eAAe,cAAc,CAAA"}
|
package/dist/lib/config.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getApiRoute = exports.getAuthApiRoute = exports.getLogoutApiRoute = exports.getLoginApiRoute = exports.getConfig = exports.configure = exports.isConfigured = void 0;
|
|
7
|
-
const core_1 = require("@hellocoop/core");
|
|
8
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
-
dotenv_1.default.config();
|
|
10
|
-
const HELLO_API_ROUTE = process.env.HELLO_API_ROUTE || '/api/hellocoop';
|
|
11
|
-
const HELLO_DOMAIN = process.env.HELLO_DOMAIN || 'hello.coop';
|
|
12
|
-
const _configuration = {
|
|
13
|
-
production: process.env.NODE_ENV === 'production',
|
|
14
|
-
routes: {
|
|
15
|
-
loggedIn: '/',
|
|
16
|
-
loggedOut: '/',
|
|
17
|
-
},
|
|
18
|
-
cookies: {
|
|
19
|
-
authName: 'hellocoop_auth',
|
|
20
|
-
oidcName: 'hellocoop_oidc',
|
|
21
|
-
},
|
|
22
|
-
callbacks: {},
|
|
23
|
-
apiRoute: HELLO_API_ROUTE,
|
|
24
|
-
authApiRoute: HELLO_API_ROUTE + '?auth=true',
|
|
25
|
-
loginApiRoute: HELLO_API_ROUTE + '?login=true',
|
|
26
|
-
logoutApiRoute: HELLO_API_ROUTE + '?logout=true',
|
|
27
|
-
// configured only by process.env or .env
|
|
28
|
-
clientId: process.env.HELLO_CLIENT_ID,
|
|
29
|
-
secret: process.env.HELLO_COOKIE_SECRET,
|
|
30
|
-
host: undefined,
|
|
31
|
-
redirectURI: process.env.HELLO_REDIRECT_URI
|
|
32
|
-
|| process.env.HELLO_HOST
|
|
33
|
-
? `https://${process.env.HELLO_HOST}${HELLO_API_ROUTE}`
|
|
34
|
-
: undefined,
|
|
35
|
-
// for internal testing
|
|
36
|
-
helloDomain: HELLO_DOMAIN,
|
|
37
|
-
helloWallet: process.env.HELLO_WALLET
|
|
38
|
-
|| 'https://wallet.' + HELLO_DOMAIN,
|
|
39
|
-
};
|
|
40
|
-
exports.isConfigured = false;
|
|
41
|
-
const pendingConfigurations = [];
|
|
42
|
-
const configure = function (config) {
|
|
43
|
-
_configuration.clientId = process.env.HELLO_CLIENT_ID || config.client_id;
|
|
44
|
-
if (config.routes) {
|
|
45
|
-
_configuration.routes = {
|
|
46
|
-
..._configuration.routes,
|
|
47
|
-
...config.routes
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
_configuration.callbacks = config.callbacks || {};
|
|
51
|
-
_configuration.scope = config.scope;
|
|
52
|
-
_configuration.provider_hint = config.provider_hint;
|
|
53
|
-
exports.isConfigured = true;
|
|
54
|
-
if (!_configuration.clientId) {
|
|
55
|
-
const message = 'No HELLO_CLIENT_ID was in environment or client_id in hello.config';
|
|
56
|
-
_configuration.error = [message];
|
|
57
|
-
console.error(message);
|
|
58
|
-
exports.isConfigured = false;
|
|
59
|
-
}
|
|
60
|
-
if (!_configuration.secret) {
|
|
61
|
-
const message = 'No HELLO_COOKIE_SECRET was in environment';
|
|
62
|
-
_configuration.error = [message];
|
|
63
|
-
console.error(message);
|
|
64
|
-
exports.isConfigured = false;
|
|
65
|
-
}
|
|
66
|
-
if (_configuration.secret && !(0, core_1.checkSecret)(_configuration.secret)) {
|
|
67
|
-
const message = 'HELLO_COOKIE_SECRET is not 16 hex digits';
|
|
68
|
-
_configuration.error = [message];
|
|
69
|
-
console.error(message);
|
|
70
|
-
exports.isConfigured = false;
|
|
71
|
-
}
|
|
72
|
-
while (pendingConfigurations.length > 0) {
|
|
73
|
-
const resolve = pendingConfigurations.pop();
|
|
74
|
-
if (resolve)
|
|
75
|
-
resolve(_configuration);
|
|
76
|
-
}
|
|
77
|
-
// console.log({isConfigured})
|
|
78
|
-
// console.log({_configuration})
|
|
79
|
-
};
|
|
80
|
-
exports.configure = configure;
|
|
81
|
-
const getConfig = function () {
|
|
82
|
-
if (!exports.isConfigured) {
|
|
83
|
-
return new Promise((resolve) => {
|
|
84
|
-
pendingConfigurations.push(() => resolve(_configuration));
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return Promise.resolve(_configuration);
|
|
88
|
-
};
|
|
89
|
-
exports.getConfig = getConfig;
|
|
90
|
-
const getLoginApiRoute = () => { return _configuration.loginApiRoute; };
|
|
91
|
-
exports.getLoginApiRoute = getLoginApiRoute;
|
|
92
|
-
const getLogoutApiRoute = () => { return _configuration.logoutApiRoute; };
|
|
93
|
-
exports.getLogoutApiRoute = getLogoutApiRoute;
|
|
94
|
-
const getAuthApiRoute = () => { return _configuration.authApiRoute; };
|
|
95
|
-
exports.getAuthApiRoute = getAuthApiRoute;
|
|
96
|
-
const getApiRoute = () => { return _configuration.apiRoute; };
|
|
97
|
-
exports.getApiRoute = getApiRoute;
|
|
98
|
-
exports.default = _configuration;
|
package/dist/lib/oidc.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
export type OIDC = {
|
|
3
|
-
code_verifier: string;
|
|
4
|
-
nonce: string;
|
|
5
|
-
redirect_uri: string;
|
|
6
|
-
target_uri: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const getOidc: (req: Request, res: Response) => Promise<OIDC | undefined>;
|
|
9
|
-
export declare const saveOidc: (req: Request, res: Response, oidc: OIDC) => Promise<void>;
|
|
10
|
-
export declare const clearOidcCookie: (res: Response) => void;
|
|
11
|
-
//# sourceMappingURL=oidc.d.ts.map
|
package/dist/lib/oidc.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../../src/lib/oidc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAO3C,MAAM,MAAM,IAAI,GAAG;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,OAAO,QAAgB,OAAO,OAAO,QAAQ,KAAG,QAAQ,IAAI,GAAG,SAAS,CAepF,CAAA;AAID,eAAO,MAAM,QAAQ,QAAgB,OAAO,OAAO,QAAQ,QAAQ,IAAI,kBAetE,CAAA;AAED,eAAO,MAAM,eAAe,QAAU,QAAQ,SAK7C,CAAA"}
|
package/dist/lib/oidc.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.clearOidcCookie = exports.saveOidc = exports.getOidc = void 0;
|
|
7
|
-
const config_1 = __importDefault(require("./config"));
|
|
8
|
-
const cookie_1 = require("cookie");
|
|
9
|
-
const core_1 = require("@hellocoop/core");
|
|
10
|
-
const { cookies: { oidcName } } = config_1.default;
|
|
11
|
-
const getOidc = async (req, res) => {
|
|
12
|
-
try {
|
|
13
|
-
const cookies = (0, cookie_1.parse)(req.headers.cookie || '');
|
|
14
|
-
const oidcCookie = cookies[oidcName];
|
|
15
|
-
if (!oidcCookie)
|
|
16
|
-
return undefined;
|
|
17
|
-
const oidc = await (0, core_1.decryptObj)(oidcCookie, config_1.default.secret);
|
|
18
|
-
if (oidc) {
|
|
19
|
-
return oidc;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
(0, exports.clearOidcCookie)(res);
|
|
24
|
-
console.error(e);
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
};
|
|
28
|
-
exports.getOidc = getOidc;
|
|
29
|
-
let apiRoute = '/';
|
|
30
|
-
const saveOidc = async (req, res, oidc) => {
|
|
31
|
-
if (apiRoute === '/')
|
|
32
|
-
apiRoute = req.path;
|
|
33
|
-
try {
|
|
34
|
-
const encCookie = await (0, core_1.encryptObj)(oidc, config_1.default.secret);
|
|
35
|
-
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(oidcName, encCookie, {
|
|
36
|
-
httpOnly: true,
|
|
37
|
-
secure: config_1.default.production,
|
|
38
|
-
sameSite: 'lax',
|
|
39
|
-
maxAge: 5 * 60,
|
|
40
|
-
path: apiRoute
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
console.error(e);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
exports.saveOidc = saveOidc;
|
|
48
|
-
const clearOidcCookie = (res) => {
|
|
49
|
-
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(oidcName, '', {
|
|
50
|
-
expires: new Date(0),
|
|
51
|
-
path: apiRoute
|
|
52
|
-
}));
|
|
53
|
-
};
|
|
54
|
-
exports.clearOidcCookie = clearOidcCookie;
|