https://github.com/bayer-group/express-client-validator

An express middleware to validate route clients

https://github.com/bayer-group/express-client-validator

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.9%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

An express middleware to validate route clients

Basic Info
  • Host: GitHub
  • Owner: Bayer-Group
  • License: bsd-3-clause
  • Language: CoffeeScript
  • Default Branch: master
  • Size: 105 KB
Statistics
  • Stars: 4
  • Watchers: 4
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Created almost 9 years ago · Last pushed about 1 year ago
Metadata Files
Readme Contributing License

README.md

Client Validator for Express routes

The purpose of this module is to be plugged in as a middleware when an app needs to validate the requests are coming from allowable clients.

Install the module

npm install save express-client-validator

Usage

RouteClientValidator = require 'express-client-validator'
{validator} = RouteClientValidator

Initialize the restricted routes and pass it to the validator during configuration

e.g. routes = [ { url : '/' methods : ['GET','PUT','POST','DELETE'] clientIds : ['CLIENT-A'] } { url : '/route-1/?' methods : ['GET','PUT','POST','DELETE'] clientIds : ['CLIENT-A','CLIENT-C'] } ] The middleware takes in a list of restricted routes which means the client is free to choose the store for its route definitions. E.g. it could be stored either in a database, or as part of CF service bindings or maybe a bundled json in the app
1. Below configuration will use the default client-id as the header param to lookup in the request e.g.

`RouteClientValidator.configure({routes})`
  1. If the clientId is stored in a custom header you can pass it as headerClientKey during config e.g.

    RouteClientValidator.configure({headerClientKey:'custom_client_id', routes})

Configure the middleware

Given app is the express router, the validator can be configured as below

app.use '/', validator

Fire up the app and now all the routes would be validated as per the restrictions defined during configuration

Routes are

The list of routes should contain at least one route definition

| property | validations | | :------- | :---------- | | url | has to be non empty string | | method | should be a string array containing at least one http method e.g. ['GET','PUT'] etc. | | clientIds | should be a list of client ids that are allowed for the given url. If the endpoint needs to be open for all leave it as empty array [] |

How to define routes

| url | method | cliendIds | What does it mean | | :-- | :----- | :-------- | :---------------- | | /route-1 | ['PUT','POST','DELETE'] | ['CLIENT-A'] | Only client CLIENT-A is allowed to call /route-1 POST, PUT, DELETE routes | | /route-1 | ['GET'] | [ ] | All clients can call the /route-1 GET endpoint | | / | ['GET','HEAD','PUT','POST','DELETE'] | ['CLIENT-B'] | Only client CLIENT-B is allowed to call / GET, HEAD, POST, PUT, DELETE routes |

Note: The restricted routes are evaluated by matching from distinct to partial matches.

e.g. in the above table since client CLIENT-B is allowed for / means an endpoint like /route-2 is allowed to CLIENT-B but not any other clients

however CLIENT-B will not be allowed to call /route-1 endpoint since it is restricted to client CLIENT-A

If CLIENT-B needs to access /route-1 as well then it needs to be explicitly defined

e.g routes = [ { url : '/route-1' methods : ['PUT','POST','DELETE'] clientIds : ['CLIENT-A','CLIENT-B'] } ]

URL path params can be specified with a ? which the validator will replace with this regex ([-A-z0-9@:%$_\+.~#])+ for pattern matching ``` e.g. defining a route url like below routes = [ { url : '/route-1/?/child-route' ... } ]

will match request with urls like

/route-1/xyz/child-route /route-1/1234/child-route /route-1/xyz-00$1/child-route

```

Query params are automatically handled by the validator by matching using this regex ([-A-z0-9\/?@:%$_&=\+.~#])*

Owner

  • Name: Bayer Open Source
  • Login: Bayer-Group
  • Kind: organization

Science for a better life

GitHub Events

Total
  • Delete event: 6
  • Issue comment event: 5
  • Push event: 5
  • Pull request review comment event: 2
  • Pull request review event: 7
  • Pull request event: 9
  • Fork event: 1
  • Create event: 1
Last Year
  • Delete event: 6
  • Issue comment event: 5
  • Push event: 5
  • Pull request review comment event: 2
  • Pull request review event: 7
  • Pull request event: 9
  • Fork event: 1
  • Create event: 1

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 14
  • Total Committers: 6
  • Avg Commits per committer: 2.333
  • Development Distribution Score (DDS): 0.643
Past Year
  • Commits: 8
  • Committers: 2
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.375
Top Committers
Name Email Commits
Bryan Young b****g@b****m 5
Dylan Jager-Kujawa d****t@b****m 3
Garrett Long g****t@b****m 2
akuma11 a****r@m****m 2
Bryan Young b****g@m****m 1
Prasanna Crasta p****s@m****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 1
  • Total pull requests: 9
  • Average time to close issues: 12 days
  • Average time to close pull requests: over 1 year
  • Total issue authors: 1
  • Total pull request authors: 5
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.56
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 5
Past Year
  • Issues: 0
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 22 hours
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • akuma1 (1)
Pull Request Authors
  • dependabot[bot] (10)
  • b-r-y-a-n (2)
  • Kujawadl (2)
  • akuma1 (1)
  • elyku (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (10)

Packages

  • Total packages: 1
  • Total downloads:
    • npm 509 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 5
  • Total maintainers: 3
npmjs.org: express-client-validator

The purpose of this module is to be plugged in as a middleware when an app needs to validate the requests are coming from allowable clients.

  • Versions: 5
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 509 Last month
Rankings
Downloads: 4.6%
Forks count: 8.9%
Dependent repos count: 10.4%
Average: 11.4%
Stargazers count: 12.3%
Dependent packages count: 21.0%
Maintainers (3)
Last synced: 11 months ago

Dependencies

package-lock.json npm
  • 170 dependencies
package.json npm
  • chai ~4.2.0 development
  • chai-as-promised ~7.1.1 development
  • coffeescript ~2.5.1 development
  • mocha ~8.1.3 development
  • sinon ~1.17.7 development
  • sinon-as-promised ~4.0.3 development
  • sinon-chai ~3.5.0 development
  • ajv ~4.8.2
  • underscore ~1.12.1