Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
exports.createPassportOptions = function createPassportOptions(options) { | ||
const auth = options.auth || {}; | ||
|
||
const authenticate = (data, done) => { | ||
const name = data.name; | ||
if (name === auth.user | ||
&& data.password === auth.password) return done(null, { name }); | ||
|
||
const err = new Error('Invalid Login') | ||
err.status = 401; | ||
done(err); | ||
}; | ||
|
||
const serializeNPMToken = (data, done) => { | ||
const name = data.name; | ||
const password = data.password; | ||
try { | ||
const token = JSON.stringify({ | ||
name, | ||
password | ||
}); | ||
done(null, token); | ||
} | ||
catch (stringifyError) { | ||
done(stringifyError); | ||
} | ||
}; | ||
|
||
const deserializeNPMToken = (data, done) => { | ||
try { | ||
const req = data.req; | ||
const tokenData = JSON.parse(data.token); | ||
const name = tokenData.name; | ||
const password = tokenData.password; | ||
authenticate({ | ||
req, | ||
name, | ||
password: password | ||
}, done); | ||
} | ||
catch (deserializeError) { | ||
done(deserializeError); | ||
} | ||
}; | ||
|
||
return { | ||
authenticate, | ||
serializeNPMToken, | ||
deserializeNPMToken | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "passport-npm-basic", | ||
"version": "1.0.0", | ||
"description": "basic auth option creator for passport-npm", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": ["passport", "passport-npm"], | ||
"author": "Jarrett Cruger", | ||
"license": "MIT" | ||
} |