@gparency/authorizer
TypeScript icon, indicating that this package has built-in type declarations

2.2.6 • Public • Published

GParency Authorize Decorator

Release to NPMJS Status Npm package version Minimum node.js version

About

This is NPM package containing the @Authorize decorator that is used for authorizing access to GParency lambda functions. The authorizer injects the authorized user payload in the event if user is authorized.

requestContext.authorizer injected into API Gateway event:

{
    "loanTrackerId": 123456789, 
    "email": "user@email.com", 
    "isGpPaid": "true | false",  
    "isMapUser": "true | false",  
    "isPaidMapUser": "true | false",  
    "isLenderPaid": "true | false",
    "isLender": "true | false",
    "isAdmin": "true | false",
    "rateAdmin": "true | false",
    "userId": "google-oauth2|103010667649373229274"
}

How to use

  1. Install the package
$ npm install @gparency/authorizer
  1. Add decorator to handler methods
class Handler {
    /**
     * Get Profile
     * @param event APIGatewayProxyEvent
     * @param _context Context
     */
    @Authorize(AuthorizationLevel.IS_GP_PAID)
    public async getProfile(event: APIGatewayProxyEvent, _context: Context): Promise<APIGatewayProxyStructuredResultV2> {
        const service = await this.getService({ event });
        try {
            return GatewayResponse.ok(await service.getProfile());
        } catch (exception) {
            Logger.error(exception);
            return GatewayErrorResponse.fromError(exception);
        }
    }
}

Levels of authorization

There are six levels of authorization:

  1. @Authorize(): This is only checking if the user is authenticated and has a valid JWT.
  2. @Authorize(AuthorizationLevel.IS_GP_PAID): This checks if the user is GP Paid member.
  3. @Authorize(AuthorizationLevel.IS_MAP_USER): This checks if the user is registered for the Map.
  4. @Authorize(AuthorizationLevel.IS_PAID_MAP_USER): This checks if the user is paid for the Map.
  5. @Authorize(AuthorizationLevel.IS_LENDER_PAID): This checks if the user is Lender Paid member.
  6. @Authorize(AuthorizationLevel.IS_LENDER): This checks if the user is a Lender member.

Additional claims:

  • userId - Id of the logged in user.

Required Environment Variables

AUTH0_AUDIENCE="..."
AUTH0_ISSUER="..."
AUTH0_SIGNING_CERT="..."

Readme

Keywords

none

Package Sidebar

Install

npm i @gparency/authorizer

Weekly Downloads

3

Version

2.2.6

License

MIT

Unpacked Size

152 kB

Total Files

31

Last publish

Collaborators

  • abrar.qureshi
  • rmoddel