Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function setupBindings2() {
addExtension(
app,
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
PassportBasicAuthProvider,
{
namespace:
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
},
);
// used by VerifyFunctionProvider
app.bind(USERS_REPOSITORY_BINDING_KEY).to(users);
// the verify function for passport-http
app
.bind(VERIFY_FUNCTION_BASIC_AUTHENTICATION_BINDING_KEY)
.toProvider(VerifyFunctionProvider);
// used by the Strategy Adapter
async function setupBindings2() {
addExtension(
app,
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
PassportBasicAuthProvider,
{
namespace:
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
},
);
// used by VerifyFunctionProvider
app.bind(USERS_REPOSITORY_BINDING_KEY).to(users);
// the verify function for passport-http
app
.bind(VERIFY_FUNCTION_BASIC_AUTHENTICATION_BINDING_KEY)
.toProvider(VerifyFunctionProvider);
// used by the Strategy Adapter
app
.bind(AuthenticationBindings.USER_PROFILE_FACTORY)
.to(myUserProfileFactory);
}
namespace:
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
},
);
// used by VerifyFunctionProvider
app.bind(USERS_REPOSITORY_BINDING_KEY).to(users);
// the verify function for passport-http
app
.bind(VERIFY_FUNCTION_BASIC_AUTHENTICATION_BINDING_KEY)
.toProvider(VerifyFunctionProvider);
// used by the Strategy Adapter
app
.bind(AuthenticationBindings.USER_PROFILE_FACTORY)
.to(myUserProfileFactory);
}
constructor(
// The provider is instantiated for Sequence constructor,
// at which time we don't have information about the current
// route yet. This information is needed to determine
// what auth strategy should be used.
// To solve this, we are injecting a getter function that will
// defer resolution of the strategy until authenticate() action
// is executed.
@inject.getter(AuthenticationBindings.STRATEGY)
readonly getStrategy: Getter,
@inject.setter(AuthenticationBindings.CURRENT_USER)
readonly setCurrentUser: Setter,
) {}
super(options);
// Set up the custom sequence
this.sequence(MySequence);
// Set up default home page
this.static('/', path.join(__dirname, '../public'));
// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
});
this.component(RestExplorerComponent);
// this.component(AuthenticationComponent);
this.bind(AuthenticationBindings.METADATA).toProvider(MyAuthMetadataProvider);
this.bind(MyAuthBindings.STRATEGY).toProvider(MyAuthAuthenticationStrategyProvider);
this.bind(AuthenticationBindings.AUTH_ACTION).toProvider(MyAuthActionProvider);
this.projectRoot = __dirname;
// Customize @loopback/boot Booter Conventions here
this.bootOptions = {
controllers: {
// Customize ControllerBooter Conventions here
dirs: ['controllers'],
extensions: ['.controller.js'],
nested: true,
},
};
}
// Set up the custom sequence
this.sequence(MySequence);
// Set up default home page
this.static('/', path.join(__dirname, '../public'));
// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
});
this.component(RestExplorerComponent);
// this.component(AuthenticationComponent);
this.bind(AuthenticationBindings.METADATA).toProvider(MyAuthMetadataProvider);
this.bind(MyAuthBindings.STRATEGY).toProvider(MyAuthAuthenticationStrategyProvider);
this.bind(AuthenticationBindings.AUTH_ACTION).toProvider(MyAuthActionProvider);
this.projectRoot = __dirname;
// Customize @loopback/boot Booter Conventions here
this.bootOptions = {
controllers: {
// Customize ControllerBooter Conventions here
dirs: ['controllers'],
extensions: ['.controller.js'],
nested: true,
},
};
}
});
this.setUpBindings();
// Bind authentication component related elements
this.component(AuthenticationComponent);
this.component(AuthorizationComponent);
// authorization
this.bind('casbin.enforcer').toDynamicValue(createEnforcer);
this.bind('authorizationProviders.casbin-provider')
.toProvider(CasbinAuthorizationProvider)
.tag(AuthorizationTags.AUTHORIZER);
// authentication
registerAuthenticationStrategy(this, JWTAuthenticationStrategy);
// Set up the custom sequence
this.sequence(MyAuthenticationSequence);
// Set up default home page
this.static('/', path.join(__dirname, '../public'));
// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
});
this.component(RestExplorerComponent);
this.projectRoot = __dirname;
// Customize @loopback/boot Booter Conventions here
this.bootOptions = {
constructor(options: ApplicationConfig = {}) {
super(options);
//add
// Bind authentication component related elements
this.component(AuthenticationComponent);
// Bind JWT & permission authentication strategy related elements
registerAuthenticationStrategy(this, JWTStrategy);
this.bind(MyAuthBindings.TOKEN_SERVICE).toClass(JWTService);
this.bind(MyAuthBindings.USER_PERMISSIONS).toProvider(UserPermissionsProvider);
// Set up the custom sequence
this.sequence(MySequence);
// Set up default home page
this.static('/', path.join(__dirname, '../public'));
// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
});
this.component(RestExplorerComponent);
this.projectRoot = __dirname;
// Customize @loopback/boot Booter Conventions here
constructor(
// The provider is instantiated for Sequence constructor,
// at which time we don't have information about the current
// route yet. This information is needed to determine
// what auth strategy should be used.
// To solve this, we are injecting a getter function that will
// defer resolution of the strategy until authenticate() action
// is executed.
@inject.getter(AuthenticationBindings.STRATEGY)
readonly getStrategy: Getter,
@inject.setter(AuthenticationBindings.CURRENT_USER)
readonly setCurrentUser: Setter,
) {}
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
) {}
@authenticate(AUTH_STRATEGY_NAME)
async whoAmI(): Promise {
return this.user.id;
}
}
app.controller(MyController);
}