This commit is contained in:
Timo Hocker 2020-03-04 13:53:23 +01:00
commit a99162320b
6 changed files with 3247 additions and 0 deletions

17
.eslintrc.js Normal file
View File

@ -0,0 +1,17 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true
},
extends: [
'@scode'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018
}
}

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/node_modules/
/dist/
/.nyc_output/
/coverage/

1
.npmrc Normal file
View File

@ -0,0 +1 @@
@scode:registry=https://npm.scode.ovh

44
index.js Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* Created by Timo Hocker <timo@scode.ovh>, January 2020
*/
/* eslint-disable no-magic-numbers */
// @ts-nocheck
'use strict';
const crypto = require ('@scode/crypto-helper');
const http_consts = require ('@scode/consts');
const fetch = require ('node-fetch');
/**
* login
*
* @param {string} user username
* @param {string} password plain text password
* @param {string} host host to login on
*/
async function login (user, password, host = '') {
const salt_str = await fetch (`${host}/auth`, { headers: { user } })
.then ((res) => {
if (res.status !== http_consts.status_ok)
return new Promise ((resolve) => resolve (''));
return res.text ();
});
if (salt_str === '')
throw new Error ('user or password invalid');
const key = crypto.hash_sha512 (password, salt_str);
return fetch (`${host}/auth`, { headers: { user, key } })
.then ((res) => {
if (res.status !== http_consts.status_ok)
throw new Error ('user or password invalid');
return res.text ();
});
}
module.exports = { login };

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "auth-client-helper",
"version": "1.0.0",
"main": "index.js",
"author": "Timo Hocker <t-hocker@web.de>",
"license": "MIT",
"devDependencies": {
"@scode/eslint-config": "^1.2.25",
"ava": "^3.5.0",
"eslint": "^6.8.0",
"nyc": "^15.0.0"
},
"scripts": {
"lint": "eslint .",
"test": "nyc ava"
},
"dependencies": {
"@scode/consts": "^1.0.1",
"@scode/crypto-helper": "^1.0.2"
}
}

3160
yarn.lock Normal file

File diff suppressed because it is too large Load Diff