@remap/authenticate-middleware
Advanced tools
Comparing version 1.0.2 to 1.1.0
const { STATUS_CODES } = require('http') | ||
const { createError } = require('micro-errors') | ||
const { Authentication } = require('@remap/services') | ||
@@ -9,3 +10,3 @@ const STATUS_MESSAGE_400 = STATUS_CODES[400] | ||
module.exports = ({ authenticate }) => { | ||
module.exports = ({ authenticate = Authentication.authenticate } = {}) => { | ||
if (typeof authenticate !== 'function') { | ||
@@ -28,5 +29,3 @@ throw new TypeError('`authenticate` service client must be function') | ||
const auth = await authenticate(idToken).catch(error => { | ||
throw createError(401, STATUS_MESSAGE_401, error, { detail: 'Invalid token' }) | ||
}) | ||
const auth = await authenticate(idToken).catch(error => { throw error }) | ||
@@ -33,0 +32,0 @@ if (!auth) { |
{ | ||
"name": "@remap/authenticate-middleware", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "ReMap Authenticate Middleware", | ||
@@ -30,2 +30,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@remap/services": "^1.1.0", | ||
"micro-errors": "^2.0.0" | ||
@@ -35,2 +36,3 @@ }, | ||
"ava": "^1.0.0-beta.8", | ||
"cross-fetch": "^2.2.2", | ||
"eslint": "^5.5.0", | ||
@@ -41,5 +43,4 @@ "eslint-plugin-ava": "^5.1.1", | ||
"micro-compose": "^0.0.3", | ||
"node-fetch": "^2.2.0", | ||
"test-listen": "^1.1.0" | ||
} | ||
} |
@@ -14,8 +14,7 @@ # authenticate-middleware | ||
const { handleErrors } = require('micro-errors') | ||
const auhtenticate = require('@remap/authenticate-middleware') | ||
const authenticationService = require('./services/authentication') | ||
const authenticateMiddleware = require('@remap/authenticate-middleware') | ||
module.exports = compose( | ||
handleErrors(), | ||
authenticate({ authentication: authenticationServive }) | ||
authenticateMiddleware(), | ||
)( | ||
@@ -26,14 +25,10 @@ async (req, res) => { | ||
) | ||
``` | ||
// ./services/authentication example | ||
### Optional custom authenticator | ||
module.exports = async idToken => { | ||
const res = await fetch(process.env.AUTHENTICATION_ENDPOINT, { | ||
method: 'POST', | ||
body: JSON.stringify({ id_token: idToken }), | ||
mode: 'cors', | ||
}) | ||
return await res.json() | ||
} | ||
```js | ||
const middlwware = authenticateMiddleware({ | ||
authenticate: async () => await doSomething(), | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3021
3
30
33
2
+ Added@remap/services@^1.1.0
+ Added@remap/services@1.1.0(transitive)
+ Addedcross-fetch@2.2.6(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-fetch@2.0.4(transitive)
+ Addedwhatwg-url@5.0.0(transitive)