@tanker/fake-authentication v2.0.2-alpha12
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. getPrivateIdentity() returns the private identity associated with the provided user id. If the provided user id is new, a private identity is created. Those private identities can be used to start a Tanker session.
getPublicIdentities() can be used to return a list of public identities from a list of user ids. For missing user ids, provisional identities are returned. The returned list can be passed to functions that expect a list of users to share with.
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 user id. If the user id does not exists, a new private identity is created and stored for reuse. It is guaranteed that this function will always return the same private identity given a user id.
If getPublicIdentities() was called before getPrivateIdentity() for a given user id, a private provisional identity is also returned by getPrivateIdentity(). This provisional identity may have been used to share with that user id before it was registered on Tanker. Note that the provisional identity must be associated with the private identity (either automatically with FileKit, VerificationUI or using attachProvisionalIdentity()) to enable access to the resources shared with the provisional identity, before the user id was registered with Tanker.
From an email
const userId = 'cedric@sample.com';
const { privateIdentity, privateProvisionalIdentity } = await fakeAuth.getPrivateIdentity(userId);From a user id
const userId = 'silvie';
const { privateIdentity, privateProvisionalIdentity } = await fakeAuth.getPrivateIdentity(userId);Using a generated user id
generateUserId() can be used to create disposable or anonymous identities. In that case no provisional identity will be returned.
const userId = fakeAuth.generateUserId();
const { privateIdentity } = await fakeAuth.getPrivateIdentity(userId);Generate a user id
generateUserId() generates a random user id that can be given to getPrivateIdentity() to generate disposable or anonymous identities.
const userId = await fakeAuth.generateUserId();Get public identities
getPublicIdentities() returns an array of public identities from an array of user ids. The order of the returned public identities is guaranteed to match the order of the provided user ids.
const userIds = ['alice@sample.io', 'bob@company.com'];
const publicIdentities = await fakeAuth.getPublicIdentities(userIds);
// then use it with Tanker or FileKit
await tanker.encrypt(someData, { shareWithUsers: publicIdentities });
await fileKit.upload(someFile, { shareWithUsers: publicIdentities });How to use Tanker Fake Authentication
Fake Authentication with FileKit
const email = 'cedric@sample.com';
const { privateIdentity, privateProvisionalIdentity } = await fakeAuth.getPrivateIdentity(email);
await fileKit.start(email, privateIdentity, privateProvisionalIdentity);Fake Authentication with FileKit (Anonymous disposable session)
In that case FileKit will start a disposable Tanker session. The session will work only once and on a single device.
const {disposablePrivateIdentity} = await fakeAuth.getDisposablePrivateIdentity();
await fileKit.startDisposableSession(disposablePrivateIdentity);Fake Authentication with Tanker
const email = 'cedric@sample.com';
const { privateIdentity, privateProvisionalIdentity } = await fakeAuth.getPrivateIdentity(email);
const status = await tanker.start(privateIdentity);
switch(status) {
case 'IDENTITY_REGISTRATION_NEEDED': {
const verificationKey = await fetchItFromYourAppServer(); // See @tanker/identity
await tanker.registerIdentity({email, verificationKey});
await tanker.attachProvisionalIdentity(privateProvisionalIdentity);
break;
}
case 'IDENTITY_VERIFICATION_NEEDED': {
const verificationKey = await fetchItFromYourAppServer(); // See @tanker/identity
await tanker.verifyIdentity(verificationKey);
break;
}
}Fake Authentication using the verification UI
const email = 'cedric@sample.com';
const { privateIdentity, privateProvisionalIdentity } = await fakeAuth.getPrivateIdentity(email);
const tanker = new Tanker(config);
// The verification UI will start Tanker
const verificationUI = new VerificationUI(tanker);
await verificationUI.start(email, privateIdentity, privateProvisionalIdentity);
// Once start is done, Tanker is in a ready state3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago