1.0.8 • Published 8 months ago

minaroid-sharedmodules v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

APP-Utilities

Common Library for any looback4 application

Usage

you should put repo url in package config int he following format

"sdkcommon": "git+https://bitbucket.services.tra.gov.ae/scm/ei/app-utilities.git"

then use the library content by import what you need in the consumer

to build the library it self after modification , please Run the following command , it will create the dist folder and should be pushed to the master branch : 

tsc

Content

Helpers

contains common helper classes (enums,error-catcher ,log-message ,message-queue)

Interceptors

contains looback 4 interceptor implementation to log requests and errors

Authentication & Authorization (For Consumers)

Package Installation: "@loopback/authentication": "^3.2.4", "@loopback/authorization": "^0.4.6", "passport": "^0.4.1", "passport-http": "^0.3.0",

Index.ts

app.component(AuthenticationComponent);

// register your custom authentication strategy registerAuthenticationStrategy(app, BasicAuthenticationStrategy);

app .bind('authorizationProviders.my-provider') .toProvider(MyAuthorizationProvider) .tag(AuthorizationTags.AUTHORIZER);

app.component(AuthorizationComponent);

Sequesnce.ts

@inject(AuthenticationBindings.AUTH_ACTION) protected authenticateRequest: AuthenticateFn,

const route = this.findRoute(request);

  //call authentication action
  await this.authenticateRequest(request);

} catch (error) {

  if (
    error.code === AUTHENTICATION_STRATEGY_NOT_FOUND ||
    error.code === USER_PROFILE_NOT_FOUND
  ) {
    Object.assign(error, { statusCode: 401 /* Unauthorized */ });
  }

  this.reject(context, error);
}

Controller:

@authenticate('basic') @authorize({ allowedRoles: 'strategy' })