-
Notifications
You must be signed in to change notification settings - Fork 208
/
strategy.resolver.provider.ts
35 lines (33 loc) · 1.11 KB
/
strategy.resolver.provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: loopback4-example-shopping
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {Provider, ValueOrPromise} from '@loopback/core';
import {inject} from '@loopback/context';
import {
AuthenticationBindings,
AuthenticationMetadata,
} from '@loopback/authentication';
import {JWTStrategy} from '../authentication-strategies/JWT.strategy';
import {JWTAuthenticationBindings} from '../keys';
export class StrategyResolverProvider
implements Provider<JWTStrategy | undefined> {
constructor(
@inject(AuthenticationBindings.METADATA)
private metadata: AuthenticationMetadata,
@inject(JWTAuthenticationBindings.STRATEGY)
private jwt_strategy: JWTStrategy,
) {}
value(): ValueOrPromise<JWTStrategy | undefined> {
if (!this.metadata) {
return;
}
const name = this.metadata.strategy;
// This should be extensible
if (name === 'jwt') {
return this.jwt_strategy;
} else {
throw new Error(`The strategy ${name} is not available.`);
}
}
}