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/auth
Usage
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.js
A CommonJS bundle, suitable for use in Node.js, thatrequire
s the external dependency. This corresponds to the"main"
field in package.json -
dist/attrace-auth.esm.js
an ES module bundle, suitable for use in other people's libraries and applications, thatimport
s the external dependency. This corresponds to the"module"
field in package.json -
dist/attrace-auth.umd.js
a 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 test
Run a single test:
yarn test test/account.spec.js
Development
Directory structure:
src/ // Actual source code
assets/ // Protobuf models
test/ // Mocha tests
Run DEV server (continuously re-compiles):
yarn dev
If 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 link
In your app, use the linked package, together with the dev server this will hot reload package changes in your app.
yarn link @attrace/auth
Release new version
- Checkout latest master branch
npx np --no-tests --no-publish