0.0.5 • Published 5 years ago
@attrace/auth v0.0.5
Attrace JSClient Auth
JS library which support authentication flow.
Should work in recent browsers and NodeJS.
Install
npm install --save @attrace/auth
// of if using yarn
yarn add @attrace/authUsage
import {UserService} from '@attrace/auth'
const userServiceURL = 'http://localhost:8580'
const keyServiceURL = 'http://localhost:8581'
const service = new UserService(userServiceURL, keyServiceURL);
// Login
service.login('your@email.com', 'your_password')
// Add new/existing private key. It would throw error if you already had your key in db
const pkKey = 'IH4IQABZK2MTINY5Q5Q2EK2ETJFQGMYLA6WRTL3T5TLGZSU5RJKIPG7VEOU2VG6UMR5XJEFKFCNF6OIDVWXUUVAD6OC5J7DJJLF6LPIJ74VQ';
await service.encryptAndPOSTPrivateKey(pkKey)
// Get your private key
const pkKey = await service.requestPrivateKey()Building
yarn build builds the library to dist, generating three files:
dist/attrace-auth.cjs.jsA CommonJS bundle, suitable for use in Node.js, thatrequires the external dependency. This corresponds to the"main"field in package.jsondist/attrace-auth.esm.jsan ES module bundle, suitable for use in other people's libraries and applications, thatimports the external dependency. This corresponds to the"module"field in package.jsondist/attrace-auth.umd.jsa UMD build, suitable for use in any environment (including the browser, as a<script>tag), that includes the external dependency. This corresponds to the"browser"field in package.json
Tests
Run the tests:
yarn testRun a single test:
yarn test test/account.spec.jsDevelopment
Directory structure:
src/ // Actual source code
assets/ // Protobuf models
test/ // Mocha testsRun DEV server (continuously re-compiles):
yarn devIf you run through node against the docker devnet (devnet has a cert chain issue):
// Add the following line at the top of your min app file.
// Warning: this accepts invalid certificates, do this only in a local dev setup and make sure this is not active in production...
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";If you want to locally develop and test:
Make yarn known about this repo
yarn linkIn your app, use the linked package, together with the dev server this will hot reload package changes in your app.
yarn link @attrace/authRelease new version
- Checkout latest master branch
npx np --no-tests --no-publish