0.0.20 • Published 4 months ago

@flexiloans/auth_public v0.0.20

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

Auth & Authz middleware

auth is an npm package designed to specifically authenticate and authorize APIs in Node.js applications. It provides two middleware functions: authenticate and authorize that can be easily integrated into your application to secure routes and resources.

We use JWT validations to authenticate routes.

Installation

Install the package using npm:

npm i @flexiloans/auth_public

Usage

Importing and initialising the package

import FlexiAuth from '@flexiloans/auth_public';

<!-- Base URL is where the authentication server is hosted -->
<!-- SERVICE_NAME is the name of service installing this package  -->
const AUTH_URL = "http://AUTH_URL";
const SERVICE_NAME = "FLKYC";

FlexiAuth.init(AUTH_URL);

Authenticaiton and Authorization will not work if the library is not initialised.

Middleware Functions

Use the authenticate middleware to ensure that a user is authenticated before accessing a route.

import FlexiAuth from '@flexiloans/auth_public';

app.get('/secure-route', FlexiAuth.authenticate, (req, res) => {
  res.send('You are authenticated!');
});

app.get('/public-route', (req, res) => {
  res.send('This is a public route!');
});

NOTE - /public-route does not have authenticate middleware

Use the authorize middleware is used to check if a user has the necessary permissions to access a resource

import FlexiAuth from '@flexiloans/auth_public';

app.get('/secure-route', FlexiAuth.authenticate, FlexiAuth.authorize, (req, res) => {
  res.send('You are authenticated!');
});

app.get('/public-route', (req, res) => {
  res.send('This is a public route!');
});

Error Handling

If any error occurs during authentication or authorization, the middleware will call `next(error) to let you handle the errors as needed

0.0.20

4 months ago

0.0.17

4 months ago

0.0.16

4 months ago

0.0.15

4 months ago

0.0.11

4 months ago

0.0.12

4 months ago

0.0.13

4 months ago

0.0.14

4 months ago

0.0.10

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.7

4 months ago

0.0.6

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago