Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Keytar to store logins securely #307

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"start:all": "npm-run-all -p start:app start:server",
"build:server:wo:vm2": "ttsc -p server/tsconfig.server.json && cd out-tsc/server && npx @vercel/ncc@latest build server/server.js -m -o ../../ncc -e vm2 --stats-out ../../ncc/stats.json ",
"build:server": "ttsc -p server/tsconfig.server.json && cd out-tsc/server && npx @vercel/ncc@latest build server/server.js -m -o ../../ncc --stats-out ../../ncc/stats.json",
"build:prepare:folder": "cpy ncc/index.js release --rename=memebox.js && cpy node_modules/vm2/lib/{fixasync,sandbox,contextify}.js release",
"build:prepare:folder": "cpy ncc/index.js release --rename=memebox.js && cpy node_modules/vm2/lib/{fixasync,sandbox,contextify}.js release && cpy node_modules/keytar release/ --parents",
"build:prepare": "npm run build:prod && npm run build:prepare:withoutapp",
"build:prepare:withoutapp": "npm run build:server && npm run build:prepare:folder",
"build:nexe": "npx nexe -i release/memebox.js -r dist -r release/{*.js,!memebox.js} --verbose",
"build:nexe": "npx nexe -i release/memebox.js -r dist -r release/{*.js,!memebox.js} -r '**/keytar.node' --verbose",
"build:windows": "npm run build:nexe -- -t windows-x64 -o release/out/memebox.exe",
"build:linux": "npm run build:nexe -- -t linux-x64 -o release/out/memebox-linux",
"build:macos": "npm run build:nexe -- -t mac-x64 -o release/out/memebox-macos",
"build:macos": "npm run build:nexe -- -t mac-x64 -o release/out2/memebox-macos",
"build:all": "npm run build:windows && npm run build:linux && npm run build:macos",
"build:with-electron": "npm run electron:serve-tsc && npm run build",
"electron:serve-tsc:watch": "ttsc -p tsconfig-electron.json -w -outDir out-electron",
Expand Down Expand Up @@ -110,6 +110,8 @@
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"jest": "26.6.3",
"keytar": "7.7.0",
"nexe-natives": "1.0.2",
"ng-packagr": "^11.1.3",
"npm-run-all": "4.1.5",
"ts-node": "8.10.2",
Expand Down
3 changes: 3 additions & 0 deletions server/providers/bootstrap.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Service} from "@tsed/di";
import {MediaTriggerHandler} from "./media/media-trigger.handler";
import {TwitchBootstrap} from "./twitch/twitch.bootstrap";
import {WebsocketBootstrap} from "./websockets/websocket.bootstrap";
import { KeytarService } from "./keytar.service";

/**
* This file is used to bootstrap all services that "just" do some work
Expand All @@ -14,6 +15,8 @@ export class BootstrapServices {
mediaTriggerHandler: MediaTriggerHandler,
_twitchBootstrap: TwitchBootstrap,
_websocketBootstrap: WebsocketBootstrap,
_keytarService: KeytarService
) {
_keytarService.test();
}
}
18 changes: 18 additions & 0 deletions server/providers/keytar.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Service } from "@tsed/di";

const os = require('os');
const path = require('path');

const keytar: typeof import('keytar') = require('nexe-natives')(path.join(__dirname, '..', '..', 'node_modules', 'keytar'), {
// localPath: os.tmpdir(),
removeOnExit: false,
});

@Service()
export class KeytarService {
public async test() {
const pw = await keytar.getPassword('test', 'user');

console.info({ pw });
}
}
12 changes: 6 additions & 6 deletions server/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ function extractValue<T>(
// typed version of T result doesnt work, otherwise open a PR! thank you
convertFunction: (val: string) => any = val => val
) : T | null {
const optionExists = process.argv.find(arg => arg.includes(optionPrefix));
const optionExists = process.argv.find(arg => arg.includes(optionPrefix));

if (optionExists) {
const valueOfOption = optionExists.replace(`${optionPrefix}=`, '')
if (optionExists) {
const valueOfOption = optionExists.replace(`${optionPrefix}=`, '')

return convertFunction(valueOfOption) as T;
}
return convertFunction(valueOfOption) as T;
}

return null;
return null;
}

const PORT = extractValue<number>(PORT_OPTION_PREFIX, val => +val);
Expand Down