npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leismore/authappself_handler

v3.0.2

Published

An Express.js HTTP handler of authentication and authorization services for self-owned LMOS (NodeJS) applications.

Downloads

15

Readme

authAppSelf_handler-function

An Express.js HTTP handler of authentication and authorization services for self-owned LMOS (NodeJS) applications.

Donation

Buy me a coffee via PayPal Donation

Prerequisites

Installation

npm install @leismore/authappself_handler

Test

npm test

Examples

import express = require('express');
import { LMResponse as Resp, LMResponseData as RespData } from '@leismore/response';
import {
  authAppSelf_handler_generator         as generator,
  authAppSelf_handler_generator_HostApp as GeneratorHostApp,
  authAppSelf_handler_generator_Errors  as GeneratorErrors,
  ExpressRoutingHandler                 as ExpressHandler
} from '@leismore/authappself_handler';
import { LMError } from '@leismore/lmerror';
import { error_handler_last } from '@leismore/error_handler_last';

const app  = express();
const port = 8081;
const API  = 'http://AUTH_APP_SELF_AUTHORIZER_URL';

const authError        = new LMError( {message: 'authorization failure', code: '1'}, {statusCode: '403'} );
const authAppSelfError = new LMError( {message: 'auth_app_self failure', code: '2'}, {statusCode: '503'} );
const gErrors:GeneratorErrors     = {auth:authError, authAppSelf:authAppSelfError};
const gHostApp:GeneratorHostApp   = {hostID:'YOUR_HOST_APP_ID', permission:'YOUR_PERMISSION_NAME'};
const get_handler1:ExpressHandler = generator(gHostApp, API, gErrors);

const get_handler2:ExpressHandler = (req:express.Request, res:express.Response, next:express.NextFunction) => {
    const resp = new Resp(res);
    let data:RespData = { statusCode: '200',
      headers: {'Content-Type': 'application/json'}, body: {'result': 'OK'} };
    resp.send(data);
};

app.get('/', get_handler1, get_handler2 );
app.use(error_handler_last);

app.listen(port, () => {
  console.log(`@leismore/authappself_handler testing server, listening at http://localhost:${port}`);
});

API Details

Types

ExpressRoutingHandler

import { Request, Response, NextFunction } from 'express';
type ExpressRoutingHandler = (req:Request, res:Response, next:NextFunction) => void;

authAppSelf_handler_generator_HostApp

type authAppSelf_handler_generator_HostApp = { hostID: string, permission: string };

authAppSelf_handler_generator_Errors

import { LMError } from '@leismore/lmerror';
type authAppSelf_handler_generator_Errors = { auth:LMError, authAppSelf:LMError };

The Generator: authAppSelf_handler_generator

/**
 * Generate authAppSelf_handler function.
 * @param  hostApp
 * @param  authAppSelf_api  auth_app_self:authorizer API
 * @param  errors           LMError (or sub-class) instances for authorization failure (HTTP 403) and authAppSelf failure (HTTP 503)
 */
function authAppSelf_handler_generator(
  hostApp:         authAppSelf_handler_generator_HostApp,
  authAppSelf_api: string,
  errors:          authAppSelf_handler_generator_Errors ): ExpressRoutingHandler

The Authentication / Authorization Handler

/**
 * Test the HTTP credential, if valid, pass to the next handler.
 * else
 *   Pass a LMError object to the next error handler.
 */
function authAppSelf_handler(req:express.Request, res:express.Response, next:express.NextFunction): void

Copyright

GNU Affero General Public License v3.0

Authors