Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

byu-group-mem

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byu-group-mem

Validates the group membership of a person

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

byu-group-mem

Validates the group membership of a person

Parameters:

configuration - this is an object with the follow properties:

  • wso2_request_instance - an instance of the byu-wso2-request module
  • group_name - the name of the gro-group that you want to validate against
  • [ handler ] - an optional function that can be used to format error responses. The parameters that are passed into the handler function are:
    • statusCode - the HTTP status code that corresponds to the error.
    • error - the error object that corresponds to the error. If the person ID provided in the JWT does not match a person ID in the group specified, it is considered a 401 error. The error responses that may occur are:
      • 504 - 'MembersOf Service Time Out'
      • 500 - 'Unexpected response from MembersOf Service'
      • 401 - 'User does not have the necessary privileges'

The middleware will return an JSON formatted error response to the client if one of these errors occurs. It will continue to the next middleware if the person ID found in the JWT verification step is found in the specified BYU group membership.

Example:

First you must utilize the byu-jwt package that facilitates the JWT verification for BYU. The request headers that are passed in to this function must supply the JWT authentication token in the established manner. You must also supply the well-known-url as the second parameter.

Next you must supply the byu-group-mem middleware function with the proper object and properties.

const express = require('express');
const byuJWT = require('byu-jwt');
const AuthenticationError = byuJWT.AuthenticationError;
const wso2 = require('byu-wso2-request');
const meta = require('meta-ngin');
const verify_group_mem = require('byu-group-mem');
const WELLKNOWN_URL = 'https://api.byu.edu/well-known-stuff/';
const api = express();

const clientKey = '';
const clinetSecret = '';

wso2.setOauthSettings({clientKey: clientKey, clientSecret: clientSecret, wellKnownUrl: WELLKNOWN_URL});

app.use((req, res, next) => {
  byuJWT.authenticate(req.headers, WELLKNOWN_URL)
    .then(verifiedJWTs => {
      req.verifiedJWTs = verifiedJWTs;
      next();
    })
    .catch(err => {
      if (err instanceof AuthenticationError) {
        return res.status(401).send(meta(401, err.message));
      }
      console.error(new Date().toISOString(), 'Unexpected error when determining authentication:\n', err);
      return res.status(500).send(meta(500, 'Error determining authentication'));
    });
});

app.use(verify_group_mem({
    wso2_request_instance: wso2,
    group_name: 'identity-codes-admin'
    handler: (code, error) => {
        return {my-metadata: meta(code, error))}
    }
}))

app.use('/', function () {
    //Handle all other api calls
});

app.listen(3000, function() {
    console.log('Starting server');
})

FAQs

Package last updated on 20 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc