Identity SDK
Tanker Identity generation in JavaScript for the Tanker SDK.
Installation
The preferred way of using the component is via NPM:
npm install --save @tanker/identity
API
createIdentity(appId, appSecret, userId);
Create a new Tanker identity. This identity is secret and must only be given to a user who has been authenticated by your application. This identity is used by the Tanker client SDK to open a Tanker session.
appId
The app ID. You can access it from the Tanker dashboard.
appSecret
The app secret key. A secret that you have saved right after the creation of your App.
userId
The ID of a user in your application.
createProvisionalIdentity(appId, 'email', email);
Create a Tanker provisional identity. It allows you to share a resource with a user who does not have an account in your application yet.
appId
The app ID. You can access it from the Tanker dashboard.
email
The email of the potential recipient of the resource.
getPublicIdentity(tankerIdentity);
Return the public identity from an identity. This public identity can be used by the Tanker client SDK to share encrypted resource.
tankerIdentity
A Tanker identity.
Usage
The server-side code below demonstrates a typical flow to safely deliver identities to your users:
import { createIdentity } from '@tanker/identity';
const appId = '<app-id>';
const appSecret = '<app-secret>';
async function getUserIdentity(userId) {
const isAuthenticated = checkAuth(userId);
if (!isAuthenticated) {
throw new Error('unauthorized');
}
let identity = retrieveUserIdentity(userId);
if (!identity) {
identity = await createIdentity(appId, appSecret, userId);
storeUserIdentity(userId, identity);
}
return identity;
}
Read more about user identity in the Tanker guide.