UNPKG

1.88 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10var __importDefault = (this && this.__importDefault) || function (mod) {
11 return (mod && mod.__esModule) ? mod : { "default": mod };
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14const UnAuthenticated_1 = __importDefault(require("./UnAuthenticated"));
15const index_1 = require("./index");
16/**
17 * A gate to determine of in the given context, the given Credential is
18 * authenticated or not
19 *
20 */
21class Gateway {
22 /**
23 *
24 * @param protocol
25 */
26 constructor(protocol) {
27 this.protocol = protocol;
28 /**
29 * The Gateway always holds an IdentityProviderChain
30 * as default IDP
31 */
32 this.provider = new index_1.IdentityProviderChain();
33 }
34 /**
35 * Perform the authentication process with a given context.
36 *
37 */
38 authenticate(context) {
39 return __awaiter(this, void 0, void 0, function* () {
40 const credential = yield this.protocol.resolve(context);
41 const identity = yield this.provider.provide(credential);
42 if (!identity) {
43 throw new UnAuthenticated_1.default("Identity not found");
44 }
45 return identity;
46 });
47 }
48}
49exports.default = Gateway;
50//# sourceMappingURL=Gateway.js.map
\No newline at end of file