@sphereon/ssi-express-support 0.18.2-next.3 → 0.18.2-unstable.10

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.
@@ -1,214 +1,214 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var _a;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.OpenIDConnectAuthApi = exports.getAuthenticatedUserEndpoint = exports.getIdTokenEndpoint = exports.getLogoutCallbackEndpoint = exports.getLogoutEndpoint = exports.getLoginCallbackEndpoint = exports.getLoginEndpoint = exports.oidcGetClient = exports.oidcDiscoverIssuer = void 0;
17
- const express_1 = __importDefault(require("express"));
18
- const openid_client_1 = require("openid-client");
19
- const passport_1 = __importDefault(require("passport"));
20
- const auth_utils_1 = require("./auth-utils");
21
- const express_utils_1 = require("./express-utils");
22
- const functions_1 = require("./functions");
23
- const PREFIX = (_a = process.env.PREFIX) !== null && _a !== void 0 ? _a : '';
24
- function oidcDiscoverIssuer(opts) {
25
- var _a, _b;
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const issuerUrl = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.issuerUrl) !== null && _a !== void 0 ? _a : (0, functions_1.env)('OIDC_ISSUER', PREFIX)) !== null && _b !== void 0 ? _b : 'https://auth01.test.sphereon.com/auth/realms/energy-shr';
28
- const issuer = yield openid_client_1.Issuer.discover(issuerUrl);
29
- console.log('Discovered issuer %s %O', issuer.issuer, issuer.metadata);
30
- return { issuer, issuerUrl };
31
- });
32
- }
33
- exports.oidcDiscoverIssuer = oidcDiscoverIssuer;
34
- function oidcGetClient(issuer, metadata, opts) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- // @ts-ignore
37
- return new issuer.Client(metadata, opts === null || opts === void 0 ? void 0 : opts.jwks, opts === null || opts === void 0 ? void 0 : opts.options);
38
- });
39
- }
40
- exports.oidcGetClient = oidcGetClient;
41
- function getLoginEndpoint(router, opts) {
42
- var _a, _b, _c, _d, _e, _f;
43
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
44
- console.log(`Login endpoint is disabled`);
45
- return;
46
- }
47
- const strategy = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoint) === null || _a === void 0 ? void 0 : _a.authentication) === null || _b === void 0 ? void 0 : _b.strategy;
48
- if (!strategy) {
49
- throw Error('strategy needs to be provided');
50
- }
51
- const path = (_c = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _c !== void 0 ? _c : '/authentication/login';
52
- router.get(path, (req, res, next) => {
53
- var _a;
54
- const redirectPage = (_a = req.get('referer')) !== null && _a !== void 0 ? _a : '/';
55
- req.session.redirectPage = redirectPage;
56
- next();
57
- }, passport_1.default.authenticate(strategy, Object.assign(Object.assign(Object.assign({}, (_d = opts.authentication) === null || _d === void 0 ? void 0 : _d.strategyOptions), (_f = (_e = opts.endpoint) === null || _e === void 0 ? void 0 : _e.authentication) === null || _f === void 0 ? void 0 : _f.strategyOptions), { keepSessionInfo: false }), undefined));
58
- }
59
- exports.getLoginEndpoint = getLoginEndpoint;
60
- function getLoginCallbackEndpoint(router, opts) {
61
- var _a, _b, _c, _d, _e, _f;
62
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
63
- console.log(`Auth callback endpoint is disabled`);
64
- return;
65
- }
66
- const strategy = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoint) === null || _a === void 0 ? void 0 : _a.authentication) === null || _b === void 0 ? void 0 : _b.strategy;
67
- if (!strategy) {
68
- throw Error('strategy needs to be provided');
69
- }
70
- const path = (_c = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _c !== void 0 ? _c : '/authentication/callback';
71
- router.get(path, passport_1.default.authenticate(strategy, Object.assign(Object.assign(Object.assign({}, (_d = opts.authentication) === null || _d === void 0 ? void 0 : _d.strategyOptions), (_f = (_e = opts.endpoint) === null || _e === void 0 ? void 0 : _e.authentication) === null || _f === void 0 ? void 0 : _f.strategyOptions), { keepSessionInfo: true }), undefined), (req, res, next) => {
72
- var _a, _b, _c;
73
- if (req.user) {
74
- console.log('User authenticated', (_a = req.user) === null || _a === void 0 ? void 0 : _a.name);
75
- // console.log(req.session)
76
- const redirectPage = (_b = req.session.redirectPage) !== null && _b !== void 0 ? _b : '/search';
77
- // console.log(`PRE LOGIN PAGE in callback: ${redirectPage}`)
78
- delete req.session.redirectPage;
79
- return res.redirect(redirectPage);
80
- }
81
- else {
82
- return res.redirect((_c = (0, functions_1.env)('OIDC_FRONTEND_LOGIN_URL', PREFIX)) !== null && _c !== void 0 ? _c : 'http://localhost:3001/authentication/login');
83
- }
84
- });
85
- }
86
- exports.getLoginCallbackEndpoint = getLoginCallbackEndpoint;
87
- function getLogoutEndpoint(router, client, opts) {
88
- var _a;
89
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
90
- console.log(`Logout endpoint is disabled`);
91
- return;
92
- }
93
- const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/logout';
94
- router.get(path, (req, res) => {
95
- try {
96
- if (client.endSessionUrl()) {
97
- return res.redirect(client.endSessionUrl());
98
- }
99
- else {
100
- console.log('IDP does not support end session url');
101
- return res.redirect('/authentication/logout-callback');
102
- }
103
- }
104
- catch (error) {
105
- console.log(error);
106
- return res.redirect('/authentication/logout-callback');
107
- }
108
- });
109
- }
110
- exports.getLogoutEndpoint = getLogoutEndpoint;
111
- function getLogoutCallbackEndpoint(router, opts) {
112
- var _a;
113
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
114
- console.log(`Logout callback endpoint is disabled`);
115
- return;
116
- }
117
- const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/logout-callback';
118
- router.get(path, (req, res, next) => {
119
- var _a;
120
- try {
121
- req.logout((err) => {
122
- if (err) {
123
- console.log(`Error during calling logout-callback: ${JSON.stringify(err)}`);
124
- }
125
- });
126
- return res.redirect((_a = (0, functions_1.env)('OIDC_FRONTEND_LOGOUT_REDIRECT_URL', PREFIX)) !== null && _a !== void 0 ? _a : '/');
127
- }
128
- catch (e) {
129
- return (0, express_utils_1.sendErrorResponse)(res, 500, 'An unexpected error occurred during logout callback', e);
130
- }
131
- });
132
- }
133
- exports.getLogoutCallbackEndpoint = getLogoutCallbackEndpoint;
134
- function getIdTokenEndpoint(router, client, opts) {
135
- var _a;
136
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
137
- console.log(`ID Token endpoint is disabled`);
138
- return;
139
- }
140
- const path = (_a = opts.path) !== null && _a !== void 0 ? _a : '/authentication/tokens/id';
141
- router.get(path, auth_utils_1.isUserAuthenticated, (req, res) => {
142
- if (req.session.tokens.id_token) {
143
- return res.json({ id_token: req.session.tokens.id_token });
144
- }
145
- else {
146
- return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
147
- }
148
- });
149
- }
150
- exports.getIdTokenEndpoint = getIdTokenEndpoint;
151
- function getAuthenticatedUserEndpoint(router, opts) {
152
- var _a;
153
- if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
154
- console.log(`Authenticated User endpoint is disabled`);
155
- return;
156
- }
157
- const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/user';
158
- router.get(path, auth_utils_1.isUserAuthenticated, (req, res, next) => {
159
- if (!req.user) {
160
- return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
161
- }
162
- let user = req.user;
163
- return res.json(user);
164
- });
165
- }
166
- exports.getAuthenticatedUserEndpoint = getAuthenticatedUserEndpoint;
167
- class OpenIDConnectAuthApi {
168
- get router() {
169
- return this._router;
170
- }
171
- constructor(args) {
172
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
173
- const { agent, opts } = args;
174
- this._agent = agent;
175
- (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getLogin'] });
176
- (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getIdToken'] });
177
- (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getAuthenticatedUser'] });
178
- // no need for the logout, as you these are not protected by auth
179
- this._opts = opts;
180
- this._express = args.expressSupport.express;
181
- this._router = express_1.default.Router();
182
- const features = (_a = opts === null || opts === void 0 ? void 0 : opts.enabledFeatures) !== null && _a !== void 0 ? _a : ['login', 'logout', 'id-token', 'authenticated-user'];
183
- console.log(`Authentication API enabled`);
184
- if (features.includes('login')) {
185
- getLoginEndpoint(this.router, (_b = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _b === void 0 ? void 0 : _b.getLogin);
186
- getLoginCallbackEndpoint(this.router, (_c = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _c === void 0 ? void 0 : _c.getLogin);
187
- }
188
- if (features.includes('logout')) {
189
- getLogoutEndpoint(this.router, args.client, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.getLogout);
190
- getLogoutCallbackEndpoint(this.router, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getLogout);
191
- }
192
- if (features.includes('id-token')) {
193
- if (((_f = opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getIdToken) === undefined) {
194
- throw Error('Cannot enable id-token endpoint without providing id-token endpoint options');
195
- }
196
- getIdTokenEndpoint(this.router, args.client, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.getIdToken);
197
- }
198
- if (features.includes('authenticated-user')) {
199
- getAuthenticatedUserEndpoint(this.router, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.getAuthenticatedUser);
200
- }
201
- this._express.use((_k = (_j = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _j === void 0 ? void 0 : _j.basePath) !== null && _k !== void 0 ? _k : '', this.router);
202
- }
203
- get agent() {
204
- return this._agent;
205
- }
206
- get opts() {
207
- return this._opts;
208
- }
209
- get express() {
210
- return this._express;
211
- }
212
- }
213
- exports.OpenIDConnectAuthApi = OpenIDConnectAuthApi;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ var _a;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.OpenIDConnectAuthApi = exports.getAuthenticatedUserEndpoint = exports.getIdTokenEndpoint = exports.getLogoutCallbackEndpoint = exports.getLogoutEndpoint = exports.getLoginCallbackEndpoint = exports.getLoginEndpoint = exports.oidcGetClient = exports.oidcDiscoverIssuer = void 0;
17
+ const express_1 = __importDefault(require("express"));
18
+ const openid_client_1 = require("openid-client");
19
+ const passport_1 = __importDefault(require("passport"));
20
+ const auth_utils_1 = require("./auth-utils");
21
+ const express_utils_1 = require("./express-utils");
22
+ const functions_1 = require("./functions");
23
+ const PREFIX = (_a = process.env.PREFIX) !== null && _a !== void 0 ? _a : '';
24
+ function oidcDiscoverIssuer(opts) {
25
+ var _a, _b;
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const issuerUrl = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.issuerUrl) !== null && _a !== void 0 ? _a : (0, functions_1.env)('OIDC_ISSUER', PREFIX)) !== null && _b !== void 0 ? _b : 'https://auth01.test.sphereon.com/auth/realms/energy-shr';
28
+ const issuer = yield openid_client_1.Issuer.discover(issuerUrl);
29
+ console.log('Discovered issuer %s %O', issuer.issuer, issuer.metadata);
30
+ return { issuer, issuerUrl };
31
+ });
32
+ }
33
+ exports.oidcDiscoverIssuer = oidcDiscoverIssuer;
34
+ function oidcGetClient(issuer, metadata, opts) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ // @ts-ignore
37
+ return new issuer.Client(metadata, opts === null || opts === void 0 ? void 0 : opts.jwks, opts === null || opts === void 0 ? void 0 : opts.options);
38
+ });
39
+ }
40
+ exports.oidcGetClient = oidcGetClient;
41
+ function getLoginEndpoint(router, opts) {
42
+ var _a, _b, _c, _d, _e, _f;
43
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
44
+ console.log(`Login endpoint is disabled`);
45
+ return;
46
+ }
47
+ const strategy = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoint) === null || _a === void 0 ? void 0 : _a.authentication) === null || _b === void 0 ? void 0 : _b.strategy;
48
+ if (!strategy) {
49
+ throw Error('strategy needs to be provided');
50
+ }
51
+ const path = (_c = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _c !== void 0 ? _c : '/authentication/login';
52
+ router.get(path, (req, res, next) => {
53
+ var _a;
54
+ const redirectPage = (_a = req.get('referer')) !== null && _a !== void 0 ? _a : '/';
55
+ req.session.redirectPage = redirectPage;
56
+ next();
57
+ }, passport_1.default.authenticate(strategy, Object.assign(Object.assign(Object.assign({}, (_d = opts.authentication) === null || _d === void 0 ? void 0 : _d.strategyOptions), (_f = (_e = opts.endpoint) === null || _e === void 0 ? void 0 : _e.authentication) === null || _f === void 0 ? void 0 : _f.strategyOptions), { keepSessionInfo: false }), undefined));
58
+ }
59
+ exports.getLoginEndpoint = getLoginEndpoint;
60
+ function getLoginCallbackEndpoint(router, opts) {
61
+ var _a, _b, _c, _d, _e, _f;
62
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
63
+ console.log(`Auth callback endpoint is disabled`);
64
+ return;
65
+ }
66
+ const strategy = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoint) === null || _a === void 0 ? void 0 : _a.authentication) === null || _b === void 0 ? void 0 : _b.strategy;
67
+ if (!strategy) {
68
+ throw Error('strategy needs to be provided');
69
+ }
70
+ const path = (_c = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _c !== void 0 ? _c : '/authentication/callback';
71
+ router.get(path, passport_1.default.authenticate(strategy, Object.assign(Object.assign(Object.assign({}, (_d = opts.authentication) === null || _d === void 0 ? void 0 : _d.strategyOptions), (_f = (_e = opts.endpoint) === null || _e === void 0 ? void 0 : _e.authentication) === null || _f === void 0 ? void 0 : _f.strategyOptions), { keepSessionInfo: true }), undefined), (req, res, next) => {
72
+ var _a, _b, _c;
73
+ if (req.user) {
74
+ console.log('User authenticated', (_a = req.user) === null || _a === void 0 ? void 0 : _a.name);
75
+ // console.log(req.session)
76
+ const redirectPage = (_b = req.session.redirectPage) !== null && _b !== void 0 ? _b : '/search';
77
+ // console.log(`PRE LOGIN PAGE in callback: ${redirectPage}`)
78
+ delete req.session.redirectPage;
79
+ return res.redirect(redirectPage);
80
+ }
81
+ else {
82
+ return res.redirect((_c = (0, functions_1.env)('OIDC_FRONTEND_LOGIN_URL', PREFIX)) !== null && _c !== void 0 ? _c : 'http://localhost:3001/authentication/login');
83
+ }
84
+ });
85
+ }
86
+ exports.getLoginCallbackEndpoint = getLoginCallbackEndpoint;
87
+ function getLogoutEndpoint(router, client, opts) {
88
+ var _a;
89
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
90
+ console.log(`Logout endpoint is disabled`);
91
+ return;
92
+ }
93
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/logout';
94
+ router.get(path, (req, res) => {
95
+ try {
96
+ if (client.endSessionUrl()) {
97
+ return res.redirect(client.endSessionUrl());
98
+ }
99
+ else {
100
+ console.log('IDP does not support end session url');
101
+ return res.redirect('/authentication/logout-callback');
102
+ }
103
+ }
104
+ catch (error) {
105
+ console.log(error);
106
+ return res.redirect('/authentication/logout-callback');
107
+ }
108
+ });
109
+ }
110
+ exports.getLogoutEndpoint = getLogoutEndpoint;
111
+ function getLogoutCallbackEndpoint(router, opts) {
112
+ var _a;
113
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
114
+ console.log(`Logout callback endpoint is disabled`);
115
+ return;
116
+ }
117
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/logout-callback';
118
+ router.get(path, (req, res, next) => {
119
+ var _a;
120
+ try {
121
+ req.logout((err) => {
122
+ if (err) {
123
+ console.log(`Error during calling logout-callback: ${JSON.stringify(err)}`);
124
+ }
125
+ });
126
+ return res.redirect((_a = (0, functions_1.env)('OIDC_FRONTEND_LOGOUT_REDIRECT_URL', PREFIX)) !== null && _a !== void 0 ? _a : '/');
127
+ }
128
+ catch (e) {
129
+ return (0, express_utils_1.sendErrorResponse)(res, 500, 'An unexpected error occurred during logout callback', e);
130
+ }
131
+ });
132
+ }
133
+ exports.getLogoutCallbackEndpoint = getLogoutCallbackEndpoint;
134
+ function getIdTokenEndpoint(router, client, opts) {
135
+ var _a;
136
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
137
+ console.log(`ID Token endpoint is disabled`);
138
+ return;
139
+ }
140
+ const path = (_a = opts.path) !== null && _a !== void 0 ? _a : '/authentication/tokens/id';
141
+ router.get(path, auth_utils_1.isUserAuthenticated, (req, res) => {
142
+ if (req.session.tokens.id_token) {
143
+ return res.json({ id_token: req.session.tokens.id_token });
144
+ }
145
+ else {
146
+ return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
147
+ }
148
+ });
149
+ }
150
+ exports.getIdTokenEndpoint = getIdTokenEndpoint;
151
+ function getAuthenticatedUserEndpoint(router, opts) {
152
+ var _a;
153
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
154
+ console.log(`Authenticated User endpoint is disabled`);
155
+ return;
156
+ }
157
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/authentication/user';
158
+ router.get(path, auth_utils_1.isUserAuthenticated, (req, res, next) => {
159
+ if (!req.user) {
160
+ return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
161
+ }
162
+ let user = req.user;
163
+ return res.json(user);
164
+ });
165
+ }
166
+ exports.getAuthenticatedUserEndpoint = getAuthenticatedUserEndpoint;
167
+ class OpenIDConnectAuthApi {
168
+ get router() {
169
+ return this._router;
170
+ }
171
+ constructor(args) {
172
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
173
+ const { agent, opts } = args;
174
+ this._agent = agent;
175
+ (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getLogin'] });
176
+ (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getIdToken'] });
177
+ (0, auth_utils_1.copyGlobalAuthToEndpoints)({ opts, keys: ['getAuthenticatedUser'] });
178
+ // no need for the logout, as you these are not protected by auth
179
+ this._opts = opts;
180
+ this._express = args.expressSupport.express;
181
+ this._router = express_1.default.Router();
182
+ const features = (_a = opts === null || opts === void 0 ? void 0 : opts.enabledFeatures) !== null && _a !== void 0 ? _a : ['login', 'logout', 'id-token', 'authenticated-user'];
183
+ console.log(`Authentication API enabled`);
184
+ if (features.includes('login')) {
185
+ getLoginEndpoint(this.router, (_b = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _b === void 0 ? void 0 : _b.getLogin);
186
+ getLoginCallbackEndpoint(this.router, (_c = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _c === void 0 ? void 0 : _c.getLogin);
187
+ }
188
+ if (features.includes('logout')) {
189
+ getLogoutEndpoint(this.router, args.client, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.getLogout);
190
+ getLogoutCallbackEndpoint(this.router, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getLogout);
191
+ }
192
+ if (features.includes('id-token')) {
193
+ if (((_f = opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getIdToken) === undefined) {
194
+ throw Error('Cannot enable id-token endpoint without providing id-token endpoint options');
195
+ }
196
+ getIdTokenEndpoint(this.router, args.client, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.getIdToken);
197
+ }
198
+ if (features.includes('authenticated-user')) {
199
+ getAuthenticatedUserEndpoint(this.router, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.getAuthenticatedUser);
200
+ }
201
+ this._express.use((_k = (_j = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _j === void 0 ? void 0 : _j.basePath) !== null && _k !== void 0 ? _k : '', this.router);
202
+ }
203
+ get agent() {
204
+ return this._agent;
205
+ }
206
+ get opts() {
207
+ return this._opts;
208
+ }
209
+ get express() {
210
+ return this._express;
211
+ }
212
+ }
213
+ exports.OpenIDConnectAuthApi = OpenIDConnectAuthApi;
214
214
  //# sourceMappingURL=openid-connect-rp.js.map
@@ -1,34 +1,34 @@
1
- import { BearerUser, IStaticBearerVerifyOptions } from './types';
2
- export declare class StaticBearerAuth {
3
- private readonly strategy;
4
- private static providers;
5
- private static verifyOptions;
6
- private hashTokens?;
7
- static init(strategy: string, provider?: StaticBearerUserProvider): StaticBearerAuth;
8
- private constructor();
9
- get provider(): StaticBearerUserProvider;
10
- withHashTokens(hashTokens: boolean): this;
11
- withUsers(users: BearerUser[] | BearerUser): this;
12
- addUser(user: BearerUser[] | BearerUser): this;
13
- withVerifyOptions(options: IStaticBearerVerifyOptions | string): this;
14
- connectPassport(): void;
15
- }
16
- export interface StaticBearerUserProvider {
17
- strategy: string;
18
- addUser(user: BearerUser | BearerUser[], hashToken?: boolean): void;
19
- getUser(token: string): BearerUser | undefined;
20
- hashedTokens?: boolean;
21
- }
22
- export declare class MapBasedStaticBearerUserProvider implements StaticBearerUserProvider {
23
- private readonly _strategy;
24
- private readonly _users;
25
- private readonly _hashedTokens;
26
- constructor(strategy: string, hashedTokens?: boolean);
27
- get users(): BearerUser[];
28
- get hashedTokens(): boolean;
29
- get strategy(): string;
30
- getUser(token: string): BearerUser | undefined;
31
- addUser(user: BearerUser | BearerUser[], hashToken?: boolean): void;
32
- getUsers(): BearerUser[];
33
- }
1
+ import { BearerUser, IStaticBearerVerifyOptions } from './types';
2
+ export declare class StaticBearerAuth {
3
+ private readonly strategy;
4
+ private static providers;
5
+ private static verifyOptions;
6
+ private hashTokens?;
7
+ static init(strategy: string, provider?: StaticBearerUserProvider): StaticBearerAuth;
8
+ private constructor();
9
+ get provider(): StaticBearerUserProvider;
10
+ withHashTokens(hashTokens: boolean): this;
11
+ withUsers(users: BearerUser[] | BearerUser): this;
12
+ addUser(user: BearerUser[] | BearerUser): this;
13
+ withVerifyOptions(options: IStaticBearerVerifyOptions | string): this;
14
+ connectPassport(): void;
15
+ }
16
+ export interface StaticBearerUserProvider {
17
+ strategy: string;
18
+ addUser(user: BearerUser | BearerUser[], hashToken?: boolean): void;
19
+ getUser(token: string): BearerUser | undefined;
20
+ hashedTokens?: boolean;
21
+ }
22
+ export declare class MapBasedStaticBearerUserProvider implements StaticBearerUserProvider {
23
+ private readonly _strategy;
24
+ private readonly _users;
25
+ private readonly _hashedTokens;
26
+ constructor(strategy: string, hashedTokens?: boolean);
27
+ get users(): BearerUser[];
28
+ get hashedTokens(): boolean;
29
+ get strategy(): string;
30
+ getUser(token: string): BearerUser | undefined;
31
+ addUser(user: BearerUser | BearerUser[], hashToken?: boolean): void;
32
+ getUsers(): BearerUser[];
33
+ }
34
34
  //# sourceMappingURL=static-bearer-auth.d.ts.map