This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@tanker/fake-authentication
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Tanker Fake Authentication

This package aims at reducing the friction when starting new projects, by delaying the integration of Tanker Identity in your application server. It interacts with a Tanker server, that stores private identities.

Note that this package must not be used in production because the returned private identities are not protected. In a production application, your application server should only return private identities through an authenticated route.

API

Construction

import FakeAuthentication from '@tanker/fake-authentication';

const fakeAuth = new FakeAuthentication({ appId });

Get a private identity

getPrivateIdentity() returns the private identity associated with the provided email. If the email does not exist, a new private identity is created and stored for reuse. It is guaranteed that this function will always return the same private identity given an email.

If getPublicIdentities() was called before getPrivateIdentity() for a given email, the private identity returned by getPrivateIdentity() also contains a provisional identity. This provisional identity may have been used to share with that email before it was registered with Tanker. Note that the provisional identity must be associated with the private identity (either automatically with VerificationUI or using attachProvisionalIdentity()) to enable access to the resources shared with the provisional identity.

const email = 'alice@example.com';
const privateIdentity = await fakeAuth.getPrivateIdentity(email);

Get public identities

getPublicIdentities() returns an array of public identities from an array of emails. The order of the returned public identities is guaranteed to match the order of the provided emails.

const emails = ['alice@example.com', 'bob@company.com'];
const publicIdentities = await fakeAuth.getPublicIdentities(emails);

// then use with Tanker
await tanker.encrypt(someData, { shareWithUsers: publicIdentities });

How to use Tanker Fake Authentication

Fake Authentication with Tanker

const email = 'alice@example.com';
const privateIdentity = await fakeAuth.getPrivateIdentity(email);
const { permanentIdentity, provisionalIdentity } = privateIdentity;

const status = await tanker.start(permanentIdentity);
switch(status) {
  case 'IDENTITY_REGISTRATION_NEEDED': {
    const verificationCode = await promptUserInput(); // See @tanker/identity
    await tanker.registerIdentity({ email, verificationCode });
    await tanker.attachProvisionalIdentity(provisionalIdentity);
    break;
  }
  case 'IDENTITY_VERIFICATION_NEEDED': {
    const verificationCode = await promptUserInput(); // See @tanker/identity
    await tanker.verifyIdentity({ email, verificationCode });
    break;
  }
}

Fake Authentication using the verification UI

const email = 'alice@example.com';
const privateIdentity = await fakeAuth.getPrivateIdentity(email);
const { permanentIdentity, provisionalIdentity } = privateIdentity;

const tanker = new Tanker(config);

// The verification UI will start Tanker
const verificationUI = new VerificationUI(tanker);
await verificationUI.start(email, permanentIdentity, provisionalIdentity);
// Once start is done, Tanker is in a ready state

Readme

Keywords

none

Package Sidebar

Install

npm i @tanker/fake-authentication

Homepage

tanker.io/

Weekly Downloads

4

Version

3.0.0

License

Apache-2.0

Unpacked Size

17 kB

Total Files

11

Last publish

Collaborators

  • jmounier
  • maximerety
  • quentin.vernot.tanker
  • tankeradmin