Auth Entity Storage Rest Client Examples
Use these snippets to integrate sign-in and user administration flows from browser or server-side TypeScript applications.
EntityStorageAuthenticationAdminRestClient
import { EntityStorageAuthenticationAdminRestClient } from '@twin.org/api-auth-entity-storage-rest-client';
const adminClient = new EntityStorageAuthenticationAdminRestClient({
endpoint: 'https://api.example.org',
pathPrefix: 'v1'
});
console.log(adminClient.className()); // EntityStorageAuthenticationAdminRestClient
await adminClient.create({
password: 'StrongPassword123',
userIdentity: 'did:example:ops',
organizationIdentity: 'did:example:core',
scope: ['admin']
});
await adminClient.update({
userIdentity: 'did:example:ops:team',
scope: ['admin', 'support']
});
import { EntityStorageAuthenticationAdminRestClient } from '@twin.org/api-auth-entity-storage-rest-client';
const adminClient = new EntityStorageAuthenticationAdminRestClient({
endpoint: 'https://api.example.org',
pathPrefix: 'v1'
});
console.log(byIdentity.userIdentity); // did:example:ops:team
EntityStorageAuthenticationRestClient
import { EntityStorageAuthenticationRestClient } from '@twin.org/api-auth-entity-storage-rest-client';
const authClient = new EntityStorageAuthenticationRestClient({
endpoint: 'https://api.example.org',
pathPrefix: 'v1',
cookieName: 'access_token'
});
console.log(authClient.className()); // EntityStorageAuthenticationRestClient
await authClient.updatePassword('correct-horse-battery-staple', 'correct-horse-battery-staple-2');
const refreshResponse = await authClient.refresh(loginResponse.token);
await authClient.logout(refreshResponse.token);
console.log(refreshResponse.expiry > 0); // true
EntityStorageAuthenticationAuditRestClient
import { EntityStorageAuthenticationAuditRestClient } from '@twin.org/api-auth-entity-storage-rest-client';
const auditClient = new EntityStorageAuthenticationAuditRestClient({
endpoint: 'https://api.example.org',
pathPrefix: 'v1'
});
console.log(auditClient.className()); // EntityStorageAuthenticationAuditRestClient
const auditEntryId = await auditClient.create({
event: 'login-success',
actorId: 'did:example:user:alice',
organizationId: 'did:example:org:core',
tenantId: 'did:example:tenant:alpha',
data: {
channel: 'web'
}
});
const auditResult = await auditClient.query(
{
actorId: 'did:example:user:alice',
event: 'login-success',
startDate: '2026-04-01T00:00:00.000Z',
endDate: '2026-04-30T23:59:59.999Z'
},
undefined,
25
);
console.log(auditEntryId); // /authentication/audit/018f2f67bb9d4a0caad8386f56df85ce
console.log(auditResult.entries.length); // 1
console.log(auditResult.cursor); // eyJpZCI6IjAxOGYyZjY3YmI5ZDRhMGNhYWQ4Mzg2ZjU2ZGY4NWNlIn0=