@sphereon/ssi-express-support 0.18.1 → 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,21 +1,21 @@
1
- import express, { NextFunction, RequestHandler } from 'express';
2
- import { ParamsDictionary } from 'express-serve-static-core';
3
- import { ParsedQs } from 'qs';
4
- import { EndpointArgs, HasEndpointOpts } from './types';
5
- export declare const checkUserIsInRole: (opts: {
6
- roles: string | string[];
7
- }) => (req: express.Request, res: express.Response, next: NextFunction) => void | express.Response<any, Record<string, any>>;
8
- export declare const checkAuthenticationOnly: (opts?: EndpointArgs) => (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
9
- export declare const checkAuthorizationOnly: (opts?: EndpointArgs) => (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
10
- export declare const isUserNotAuthenticated: (req: express.Request, res: express.Response, next: express.NextFunction) => void;
11
- export declare const isUserAuthenticated: (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
12
- export declare const checkAuth: (opts?: EndpointArgs) => RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[];
13
- export declare function copyGlobalAuthToEndpoint(args?: {
14
- opts?: HasEndpointOpts;
15
- key: string;
16
- }): void;
17
- export declare function copyGlobalAuthToEndpoints(args?: {
18
- opts?: HasEndpointOpts;
19
- keys: string[];
20
- }): void;
1
+ import express, { NextFunction, RequestHandler } from 'express';
2
+ import { ParamsDictionary } from 'express-serve-static-core';
3
+ import { ParsedQs } from 'qs';
4
+ import { EndpointArgs, HasEndpointOpts } from './types';
5
+ export declare const checkUserIsInRole: (opts: {
6
+ roles: string | string[];
7
+ }) => (req: express.Request, res: express.Response, next: NextFunction) => void | express.Response<any, Record<string, any>>;
8
+ export declare const checkAuthenticationOnly: (opts?: EndpointArgs) => (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
9
+ export declare const checkAuthorizationOnly: (opts?: EndpointArgs) => (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
10
+ export declare const isUserNotAuthenticated: (req: express.Request, res: express.Response, next: express.NextFunction) => void;
11
+ export declare const isUserAuthenticated: (req: express.Request, res: express.Response, next: express.NextFunction) => void | express.Response<any, Record<string, any>>;
12
+ export declare const checkAuth: (opts?: EndpointArgs) => RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[];
13
+ export declare function copyGlobalAuthToEndpoint(args?: {
14
+ opts?: HasEndpointOpts;
15
+ key: string;
16
+ }): void;
17
+ export declare function copyGlobalAuthToEndpoints(args?: {
18
+ opts?: HasEndpointOpts;
19
+ keys: string[];
20
+ }): void;
21
21
  //# sourceMappingURL=auth-utils.d.ts.map
@@ -1,144 +1,144 @@
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.copyGlobalAuthToEndpoints = exports.copyGlobalAuthToEndpoint = exports.checkAuth = exports.isUserAuthenticated = exports.isUserNotAuthenticated = exports.checkAuthorizationOnly = exports.checkAuthenticationOnly = exports.checkUserIsInRole = void 0;
7
- const passport_1 = __importDefault(require("passport"));
8
- const express_utils_1 = require("./express-utils");
9
- const types_1 = require("./types");
10
- const checkUserIsInRole = (opts) => (req, res, next) => {
11
- if (!(opts === null || opts === void 0 ? void 0 : opts.roles) || opts.roles.length === 0) {
12
- return next();
13
- }
14
- const roles = Array.isArray(opts.roles) ? opts.roles : [opts.roles];
15
- if (!(req === null || req === void 0 ? void 0 : req.user) || !('role' in req.user)) {
16
- return res.status(401).end();
17
- }
18
- // @ts-ignore
19
- const hasRole = roles.find((role) => req.user.role.toLowerCase() === role.toLowerCase());
20
- if (!hasRole) {
21
- return res.status(403).end();
22
- }
23
- return next();
24
- };
25
- exports.checkUserIsInRole = checkUserIsInRole;
26
- const checkAuthenticationImpl = (req, res, next, opts) => {
27
- var _a, _b, _c, _d, _e, _f;
28
- const defaultCallback = (err, user, _info, _status) => {
29
- if (err) {
30
- const message = 'message' in err ? err.message : err;
31
- console.log('Authentication failed, error: ' + JSON.stringify(message));
32
- return next({ statusCode: 403, message });
33
- }
34
- else if (!user) {
35
- console.log('Authentication failed, no user object present in request. Redirecting to /login');
36
- // todo: configuration option
37
- return res.redirect('/authentication/login');
38
- }
39
- if (options.session) {
40
- req.logIn(user, function (err) {
41
- if (err) {
42
- return next(err);
43
- }
44
- });
45
- }
46
- /* /!*if (options.session) {
47
- req.logIn(user, function (err) {
48
- if (err) {
49
- return next(err)
50
- }
51
- return res.redirect('/')
52
- })
53
- }*!/*/
54
- return next();
55
- };
56
- if (!opts || !opts.authentication || opts.authentication.enabled === false) {
57
- return next();
58
- }
59
- if (!opts.authentication.strategy) {
60
- console.log(`Authentication enabled, but no strategy configured. All auth request will be denied!`);
61
- return res.status(401).end();
62
- }
63
- const options = Object.assign(Object.assign({}, (_a = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _a === void 0 ? void 0 : _a.strategyOptions), { authInfo: ((_b = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _b === void 0 ? void 0 : _b.authInfo) !== false, session: ((_c = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _c === void 0 ? void 0 : _c.session) !== false });
64
- const callback = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _d === void 0 ? void 0 : _d.callback) !== null && _e !== void 0 ? _e : (((_f = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _f === void 0 ? void 0 : _f.useDefaultCallback) ? defaultCallback : undefined);
65
- passport_1.default.authenticate(opts.authentication.strategy, options, callback).call(this, req, res, next);
66
- };
67
- const checkAuthorizationImpl = (req, res, next, opts) => {
68
- if (!opts || !opts.authentication || !opts.authorization || opts.authentication.enabled === false || (opts === null || opts === void 0 ? void 0 : opts.authorization.enabled) === false) {
69
- return next();
70
- }
71
- /*if (!req.isAuthenticated()) {
72
- return sendErrorResponse(res, 403, 'Authorization with an unauthenticated request is not possible')
73
- }*/
74
- const authorization = opts.authorization;
75
- if (!authorization.enforcer && (!authorization.requireUserInRoles || authorization.requireUserInRoles.length === 0)) {
76
- console.log(`Authorization enabled for endpoint, but no enforcer or roles supplied`);
77
- return res.status(401).end();
78
- }
79
- if (authorization.requireUserInRoles && authorization.requireUserInRoles.length > 0) {
80
- (0, exports.checkUserIsInRole)({ roles: authorization.requireUserInRoles });
81
- }
82
- if (authorization.enforcer) {
83
- const enforcer = authorization.enforcer;
84
- const permitted = enforcer.enforceSync(req.user, opts.resource, opts.operation);
85
- if (!permitted) {
86
- console.log(`Access to ${opts.resource} and op ${opts.operation} not allowed for ${req.user}`);
87
- return res.status(403).end();
88
- }
89
- }
90
- return next();
91
- };
92
- const checkAuthenticationOnly = (opts) => (req, res, next) => {
93
- // executeRequestHandlers(req, res, next, opts)
94
- return checkAuthenticationImpl(req, res, next, opts);
95
- };
96
- exports.checkAuthenticationOnly = checkAuthenticationOnly;
97
- const checkAuthorizationOnly = (opts) => (req, res, next) => {
98
- // executeRequestHandlers(req, res, next, opts)
99
- return checkAuthorizationImpl(req, res, next, opts);
100
- };
101
- exports.checkAuthorizationOnly = checkAuthorizationOnly;
102
- const isUserNotAuthenticated = (req, res, next) => {
103
- if (!req.user) {
104
- next();
105
- }
106
- };
107
- exports.isUserNotAuthenticated = isUserNotAuthenticated;
108
- const isUserAuthenticated = (req, res, next) => {
109
- if (!req.user) {
110
- return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
111
- }
112
- else {
113
- return next();
114
- }
115
- };
116
- exports.isUserAuthenticated = isUserAuthenticated;
117
- const checkAuth = (opts) => {
118
- const handlers = [];
119
- handlers.push((0, exports.checkAuthenticationOnly)(opts));
120
- handlers.push((0, exports.checkAuthorizationOnly)(opts));
121
- (opts === null || opts === void 0 ? void 0 : opts.handlers) && handlers.push(...opts.handlers);
122
- return handlers;
123
- };
124
- exports.checkAuth = checkAuth;
125
- function copyGlobalAuthToEndpoint(args) {
126
- var _a, _b, _c;
127
- const opts = args === null || args === void 0 ? void 0 : args.opts;
128
- const key = args === null || args === void 0 ? void 0 : args.key;
129
- if (!opts || !key || !(0, types_1.hasEndpointOpts)(opts)) {
130
- return;
131
- }
132
- if ((_a = opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
133
- if (((_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.disableGlobalAuth) === true) {
134
- return;
135
- }
136
- opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), { endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_c = opts.endpointOpts[key]) === null || _c === void 0 ? void 0 : _c.endpoint) });
137
- }
138
- }
139
- exports.copyGlobalAuthToEndpoint = copyGlobalAuthToEndpoint;
140
- function copyGlobalAuthToEndpoints(args) {
141
- args === null || args === void 0 ? void 0 : args.keys.forEach((key) => copyGlobalAuthToEndpoint({ opts: args === null || args === void 0 ? void 0 : args.opts, key }));
142
- }
143
- exports.copyGlobalAuthToEndpoints = copyGlobalAuthToEndpoints;
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.copyGlobalAuthToEndpoints = exports.copyGlobalAuthToEndpoint = exports.checkAuth = exports.isUserAuthenticated = exports.isUserNotAuthenticated = exports.checkAuthorizationOnly = exports.checkAuthenticationOnly = exports.checkUserIsInRole = void 0;
7
+ const passport_1 = __importDefault(require("passport"));
8
+ const express_utils_1 = require("./express-utils");
9
+ const types_1 = require("./types");
10
+ const checkUserIsInRole = (opts) => (req, res, next) => {
11
+ if (!(opts === null || opts === void 0 ? void 0 : opts.roles) || opts.roles.length === 0) {
12
+ return next();
13
+ }
14
+ const roles = Array.isArray(opts.roles) ? opts.roles : [opts.roles];
15
+ if (!(req === null || req === void 0 ? void 0 : req.user) || !('role' in req.user)) {
16
+ return res.status(401).end();
17
+ }
18
+ // @ts-ignore
19
+ const hasRole = roles.find((role) => req.user.role.toLowerCase() === role.toLowerCase());
20
+ if (!hasRole) {
21
+ return res.status(403).end();
22
+ }
23
+ return next();
24
+ };
25
+ exports.checkUserIsInRole = checkUserIsInRole;
26
+ const checkAuthenticationImpl = (req, res, next, opts) => {
27
+ var _a, _b, _c, _d, _e, _f;
28
+ const defaultCallback = (err, user, _info, _status) => {
29
+ if (err) {
30
+ const message = 'message' in err ? err.message : err;
31
+ console.log('Authentication failed, error: ' + JSON.stringify(message));
32
+ return next({ statusCode: 403, message });
33
+ }
34
+ else if (!user) {
35
+ console.log('Authentication failed, no user object present in request. Redirecting to /login');
36
+ // todo: configuration option
37
+ return res.redirect('/authentication/login');
38
+ }
39
+ if (options.session) {
40
+ req.logIn(user, function (err) {
41
+ if (err) {
42
+ return next(err);
43
+ }
44
+ });
45
+ }
46
+ /* /!*if (options.session) {
47
+ req.logIn(user, function (err) {
48
+ if (err) {
49
+ return next(err)
50
+ }
51
+ return res.redirect('/')
52
+ })
53
+ }*!/*/
54
+ return next();
55
+ };
56
+ if (!opts || !opts.authentication || opts.authentication.enabled === false) {
57
+ return next();
58
+ }
59
+ if (!opts.authentication.strategy) {
60
+ console.log(`Authentication enabled, but no strategy configured. All auth request will be denied!`);
61
+ return res.status(401).end();
62
+ }
63
+ const options = Object.assign(Object.assign({}, (_a = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _a === void 0 ? void 0 : _a.strategyOptions), { authInfo: ((_b = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _b === void 0 ? void 0 : _b.authInfo) !== false, session: ((_c = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _c === void 0 ? void 0 : _c.session) !== false });
64
+ const callback = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _d === void 0 ? void 0 : _d.callback) !== null && _e !== void 0 ? _e : (((_f = opts === null || opts === void 0 ? void 0 : opts.authentication) === null || _f === void 0 ? void 0 : _f.useDefaultCallback) ? defaultCallback : undefined);
65
+ passport_1.default.authenticate(opts.authentication.strategy, options, callback).call(this, req, res, next);
66
+ };
67
+ const checkAuthorizationImpl = (req, res, next, opts) => {
68
+ if (!opts || !opts.authentication || !opts.authorization || opts.authentication.enabled === false || (opts === null || opts === void 0 ? void 0 : opts.authorization.enabled) === false) {
69
+ return next();
70
+ }
71
+ /*if (!req.isAuthenticated()) {
72
+ return sendErrorResponse(res, 403, 'Authorization with an unauthenticated request is not possible')
73
+ }*/
74
+ const authorization = opts.authorization;
75
+ if (!authorization.enforcer && (!authorization.requireUserInRoles || authorization.requireUserInRoles.length === 0)) {
76
+ console.log(`Authorization enabled for endpoint, but no enforcer or roles supplied`);
77
+ return res.status(401).end();
78
+ }
79
+ if (authorization.requireUserInRoles && authorization.requireUserInRoles.length > 0) {
80
+ (0, exports.checkUserIsInRole)({ roles: authorization.requireUserInRoles });
81
+ }
82
+ if (authorization.enforcer) {
83
+ const enforcer = authorization.enforcer;
84
+ const permitted = enforcer.enforceSync(req.user, opts.resource, opts.operation);
85
+ if (!permitted) {
86
+ console.log(`Access to ${opts.resource} and op ${opts.operation} not allowed for ${req.user}`);
87
+ return res.status(403).end();
88
+ }
89
+ }
90
+ return next();
91
+ };
92
+ const checkAuthenticationOnly = (opts) => (req, res, next) => {
93
+ // executeRequestHandlers(req, res, next, opts)
94
+ return checkAuthenticationImpl(req, res, next, opts);
95
+ };
96
+ exports.checkAuthenticationOnly = checkAuthenticationOnly;
97
+ const checkAuthorizationOnly = (opts) => (req, res, next) => {
98
+ // executeRequestHandlers(req, res, next, opts)
99
+ return checkAuthorizationImpl(req, res, next, opts);
100
+ };
101
+ exports.checkAuthorizationOnly = checkAuthorizationOnly;
102
+ const isUserNotAuthenticated = (req, res, next) => {
103
+ if (!req.user) {
104
+ next();
105
+ }
106
+ };
107
+ exports.isUserNotAuthenticated = isUserNotAuthenticated;
108
+ const isUserAuthenticated = (req, res, next) => {
109
+ if (!req.user) {
110
+ return (0, express_utils_1.sendErrorResponse)(res, 401, 'Authentication required');
111
+ }
112
+ else {
113
+ return next();
114
+ }
115
+ };
116
+ exports.isUserAuthenticated = isUserAuthenticated;
117
+ const checkAuth = (opts) => {
118
+ const handlers = [];
119
+ handlers.push((0, exports.checkAuthenticationOnly)(opts));
120
+ handlers.push((0, exports.checkAuthorizationOnly)(opts));
121
+ (opts === null || opts === void 0 ? void 0 : opts.handlers) && handlers.push(...opts.handlers);
122
+ return handlers;
123
+ };
124
+ exports.checkAuth = checkAuth;
125
+ function copyGlobalAuthToEndpoint(args) {
126
+ var _a, _b, _c;
127
+ const opts = args === null || args === void 0 ? void 0 : args.opts;
128
+ const key = args === null || args === void 0 ? void 0 : args.key;
129
+ if (!opts || !key || !(0, types_1.hasEndpointOpts)(opts)) {
130
+ return;
131
+ }
132
+ if ((_a = opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
133
+ if (((_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.disableGlobalAuth) === true) {
134
+ return;
135
+ }
136
+ opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), { endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_c = opts.endpointOpts[key]) === null || _c === void 0 ? void 0 : _c.endpoint) });
137
+ }
138
+ }
139
+ exports.copyGlobalAuthToEndpoint = copyGlobalAuthToEndpoint;
140
+ function copyGlobalAuthToEndpoints(args) {
141
+ args === null || args === void 0 ? void 0 : args.keys.forEach((key) => copyGlobalAuthToEndpoint({ opts: args === null || args === void 0 ? void 0 : args.opts, key }));
142
+ }
143
+ exports.copyGlobalAuthToEndpoints = copyGlobalAuthToEndpoints;
144
144
  //# sourceMappingURL=auth-utils.js.map
@@ -1,10 +1,10 @@
1
- import { IBearerStrategyOption, IBearerStrategyOptionWithRequest } from './types';
2
- export declare class EntraIDAuth {
3
- private readonly strategy;
4
- private options?;
5
- static init(strategy: string): EntraIDAuth;
6
- private constructor();
7
- withOptions(options: IBearerStrategyOption | IBearerStrategyOptionWithRequest): this;
8
- connectPassport(): void;
9
- }
1
+ import { IBearerStrategyOption, IBearerStrategyOptionWithRequest } from './types';
2
+ export declare class EntraIDAuth {
3
+ private readonly strategy;
4
+ private options?;
5
+ static init(strategy: string): EntraIDAuth;
6
+ private constructor();
7
+ withOptions(options: IBearerStrategyOption | IBearerStrategyOptionWithRequest): this;
8
+ connectPassport(): void;
9
+ }
10
10
  //# sourceMappingURL=entra-id-auth.d.ts.map
@@ -1,61 +1,61 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.EntraIDAuth = void 0;
30
- const passport_1 = __importDefault(require("passport"));
31
- class EntraIDAuth {
32
- static init(strategy) {
33
- return new EntraIDAuth(strategy);
34
- }
35
- constructor(strategy) {
36
- this.strategy = strategy;
37
- }
38
- withOptions(options) {
39
- this.options = Object.assign(Object.assign({}, options), { passReqToCallback: 'passReqToCallback' in options ? options.passReqToCallback : false });
40
- return this;
41
- }
42
- connectPassport() {
43
- const _options = this.options;
44
- if (!_options) {
45
- throw Error('No options supplied for EntraID');
46
- }
47
- Promise.resolve().then(() => __importStar(require('passport-azure-ad'))).then((entraID) => passport_1.default.use(this.strategy, new entraID.BearerStrategy(_options, function (token, cb) {
48
- if (token) {
49
- // console.log(`token: ${JSON.stringify(token, null, 2)}`)
50
- return cb(null, token);
51
- }
52
- return cb('bearer token not found or incorrect', null);
53
- })))
54
- .catch((reason) => {
55
- console.log(reason);
56
- throw Error('Could not create bearer strategy. Did you include the "passport-azure-ad/bearer-strategy" dependency in package.json?');
57
- });
58
- }
59
- }
60
- exports.EntraIDAuth = EntraIDAuth;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.EntraIDAuth = void 0;
30
+ const passport_1 = __importDefault(require("passport"));
31
+ class EntraIDAuth {
32
+ static init(strategy) {
33
+ return new EntraIDAuth(strategy);
34
+ }
35
+ constructor(strategy) {
36
+ this.strategy = strategy;
37
+ }
38
+ withOptions(options) {
39
+ this.options = Object.assign(Object.assign({}, options), { passReqToCallback: 'passReqToCallback' in options ? options.passReqToCallback : false });
40
+ return this;
41
+ }
42
+ connectPassport() {
43
+ const _options = this.options;
44
+ if (!_options) {
45
+ throw Error('No options supplied for EntraID');
46
+ }
47
+ Promise.resolve().then(() => __importStar(require('passport-azure-ad'))).then((entraID) => passport_1.default.use(this.strategy, new entraID.BearerStrategy(_options, function (token, cb) {
48
+ if (token) {
49
+ // console.log(`token: ${JSON.stringify(token, null, 2)}`)
50
+ return cb(null, token);
51
+ }
52
+ return cb('bearer token not found or incorrect', null);
53
+ })))
54
+ .catch((reason) => {
55
+ console.log(reason);
56
+ throw Error('Could not create bearer strategy. Did you include the "passport-azure-ad/bearer-strategy" dependency in package.json?');
57
+ });
58
+ }
59
+ }
60
+ exports.EntraIDAuth = EntraIDAuth;
61
61
  //# sourceMappingURL=entra-id-auth.js.map