1 | const UnAuthenticated = require('./UnAuthenticated');
|
2 | const Aborted = require('./Aborted');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | class Gateway {
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 | constructor(protocol, provider) {
|
16 | this.protocol = protocol;
|
17 | this.provider = provider;
|
18 | }
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 | async authenticate(context) {
|
26 | const credential = await this.protocol.resolve(context);
|
27 | const identity = await this.provider.provide(credential);
|
28 |
|
29 | if (!identity) {
|
30 | throw new UnAuthenticated("Identity not found");
|
31 | }
|
32 |
|
33 | return identity;
|
34 | }
|
35 | }
|
36 |
|
37 | module.exports = Gateway;
|