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

@koopjs/auth-direct-file

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koopjs/auth-direct-file - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

9

CHANGELOG.md

@@ -5,8 +5,11 @@ # Change Log

## [1.1.0] - 2018-05-29
## Added
* new option `useHttp`. Must be a boolean. This will get added verbatim to the result of authenticationSpecification function
## [1.0.0] - 2018-05-22
### Added
* Initial release of an authentication plugin for Koop that leverages a file-based user-store.
[1.0.0]: https://github.com/koopjs/koop-core/releases/tag/v1.0.0
[1.1.0]: https://github.com/koopjs/koop-auth-direct-file/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/koopjs/koop-auth-direct-file/releases/tag/v1.0.0
var fs = require('fs')
var jwt = require('jsonwebtoken')
var validateCredentials = require('./validate-credentials')
var TOKEN_EXPIRATION_MINTUES = 60
var TOKEN_EXPIRATION_MINUTES = 60
var _useHttp
var _tokenExpirationMinutes

@@ -15,2 +16,3 @@ var _secret

* @param {integer} options.tokenExpirationMinutes - number of minutes until token expires
* @param {boolean} options.useHttp - direct consumers of authenticationSpecifcation to use HTTP instead of HTTPS
*/

@@ -27,7 +29,12 @@ function auth (secret, userStoreFilePath, options) {

_userStoreFilePath = userStoreFilePath
_tokenExpirationMinutes = options.tokenExpirationMinutes || TOKEN_EXPIRATION_MINTUES
// Ensure the useHttp option is a boolean and default to false
if (options.useHttp && typeof options.useHttp !== 'boolean') { throw new Error("\"useHttp\" must be a boolean") }
_useHttp = options.useHttp || false
// Ensure token expiration is an integer greater than 5
if (!Number.isInteger(_tokenExpirationMinutes) || _tokenExpirationMinutes < 5) { throw new Error("\"tokenExpirationMinutes\" must be an integer >= 5") }
if (options.tokenExpirationMinutes && (!Number.isInteger(options.tokenExpirationMinutes) || options.tokenExpirationMinutes < 5)) { throw new Error("\"tokenExpirationMinutes\" must be an integer >= 5") }
_tokenExpirationMinutes = options.tokenExpirationMinutes || TOKEN_EXPIRATION_MINUTES
return {

@@ -47,6 +54,7 @@ type: 'auth',

return function authenticationSpecification () {
return {
return Object.assign({
provider: providerNamespace,
secured: true
}
secured: true,
useHttp: _useHttp
})
}

@@ -53,0 +61,0 @@ }

{
"name": "@koopjs/auth-direct-file",
"version": "1.0.0",
"description": "Module for implementing a direct authentication pattern with Koop",
"version": "1.1.0",
"description": "Module for implementing a direct authentication pattern with file-based user-store in Koop",
"main": "dist/index.js",

@@ -14,3 +14,3 @@ "scripts": {

"type": "git",
"url": "git+https://github.com/koopjs/koop-auth-direct.git"
"url": "git+https://github.com/koopjs/koop-auth-direct-file.git"
},

@@ -27,5 +27,5 @@ "author": "Rich Gwozdz",

"bugs": {
"url": "https://github.com/koopjs/koop-auth-direct/issues"
"url": "https://github.com/koopjs/koop-auth-direct-file/issues"
},
"homepage": "https://github.com/koopjs/koop-auth-direct#readme",
"homepage": "https://github.com/koopjs/koop-auth-direct-file#readme",
"dependencies": {

@@ -32,0 +32,0 @@ "jsonwebtoken": "^8.2.1"

@@ -18,3 +18,3 @@ # Koop-Auth-Direct-File

let auth = require('./koop-auth-direct/src')('pass-in-your-secret', `${__dirname}/user-store.json`)
let auth = require('@koopjs/auth-direct-file')('pass-in-your-secret', `${__dirname}/user-store.json`)
koop.register(auth)

@@ -42,1 +42,10 @@

| options.tokenExpirationMinutes | <code>integer</code> | minutes until token expires (default 60) |
| options.useHttp | <code>boolean</code> | pass the `useHttp` boolean flag as part of the authenticationSpecification function result|
## Special considerations for use with [koop-ouput-geoservices](https://github.com/koopjs/koop-output-geoservices)
[koop-ouput-geoservices](https://github.com/koopjs/koop-output-geoservices) assumes that token-services occur over HTTPS. For development purposes you may wish to allow authentication to occur of HTTP. This can be done two different ways. You can add the `useHttp` option when configuring the module, which will be passed on in the result of `authenticationSpecification()` calls.
let auth = require('@koopjs/auth-direct-file')('pass-in-your-secret', `${__dirname}/user-store.json`, { useHttp: true })
koop.register(auth)
Alternatively, you can set an environment variable `KOOP_AUTH_HTTP=true`. Either of these approaches inform [koop-ouput-geoservices](https://github.com/koopjs/koop-output-geoservices) to use `http` as the protocol of the `tokenServicesUrl`.
const fs = require('fs')
const jwt = require('jsonwebtoken')
const validateCredentials = require('./validate-credentials')
const TOKEN_EXPIRATION_MINTUES = 60
const TOKEN_EXPIRATION_MINUTES = 60
let _useHttp
let _tokenExpirationMinutes

@@ -15,2 +16,3 @@ let _secret

* @param {integer} options.tokenExpirationMinutes - number of minutes until token expires
* @param {boolean} options.useHttp - direct consumers of authenticationSpecifcation to use HTTP instead of HTTPS
*/

@@ -25,7 +27,12 @@ function auth (secret, userStoreFilePath, options = {}) {

_userStoreFilePath = userStoreFilePath
_tokenExpirationMinutes = options.tokenExpirationMinutes || TOKEN_EXPIRATION_MINTUES
// Ensure the useHttp option is a boolean and default to false
if (options.useHttp && typeof options.useHttp !== 'boolean') throw new Error(`"useHttp" must be a boolean`)
_useHttp = options.useHttp || false
// Ensure token expiration is an integer greater than 5
if (!Number.isInteger(_tokenExpirationMinutes) || _tokenExpirationMinutes < 5) throw new Error(`"tokenExpirationMinutes" must be an integer >= 5`)
if (options.tokenExpirationMinutes && (!Number.isInteger(options.tokenExpirationMinutes) || options.tokenExpirationMinutes < 5)) throw new Error(`"tokenExpirationMinutes" must be an integer >= 5`)
_tokenExpirationMinutes = options.tokenExpirationMinutes || TOKEN_EXPIRATION_MINUTES
return {

@@ -45,6 +52,7 @@ type: 'auth',

return function authenticationSpecification () {
return {
return Object.assign({
provider: providerNamespace,
secured: true
}
secured: true,
useHttp: _useHttp
})
}

@@ -51,0 +59,0 @@ }

@@ -64,3 +64,23 @@ const test = require('tape')

test('tokenExpirationMinutes - invalid setting', t => {
test('authSpecOptions - useHttp: true', t => {
t.plan(3)
let optionAuth = require('../src')(secret, path.join(__dirname, '/fixtures/user-store.json'), {useHttp: true})
let authenticationSpecification = optionAuth.getAuthenticationSpecification(providerMock.name)
let result = authenticationSpecification()
t.equals(result.secured, true)
t.equals(result.provider, providerMock.name)
t.equals(result.useHttp, true)
})
test('authSpecOptions - useHttp: false', t => {
t.plan(3)
let optionAuth = require('../src')(secret, path.join(__dirname, '/fixtures/user-store.json'), {useHttp: false})
let authenticationSpecification = optionAuth.getAuthenticationSpecification(providerMock.name)
let result = authenticationSpecification()
t.equals(result.secured, true)
t.equals(result.provider, providerMock.name)
t.equals(result.useHttp, false)
})
test('tokenExpirationMinutes - invalid "tokenExpirationMinutes" setting', t => {
t.plan(1)

@@ -71,1 +91,8 @@ t.throws(function () {

})
test('tokenExpirationMinutes - invalid "useHttp" setting', t => {
t.plan(1)
t.throws(function () {
require('../src')(secret, path.join(__dirname, '/fixtures/user-store.json'), {useHttp: 'string-value'})
}, /"useHttp" must be a boolean/)
})

Sorry, the diff of this file is not supported yet

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