0.1.4 • Published 6 years ago
@jincor-tech/auth-ts-client v0.1.4
Auth client
This is a client library which encapsulates interaction with Auth service. With its help you can:
- Register users and tenants.
- Get tokens for users and tenants after authorization.
- Perform verification of tokens for users and tenants.
- Deactivate tokens for users and tenants.
- Remove users.
The user can be attached to several tenants through the field tenant. It is filled from the tenant's token in the Auth service service.
Usage
Initialize Auth client
let client = new AuthClient('http://auth:3000')
Work with Tenant
let registerResult = await client.registerTenant('test@test.com', 'Password1')
// { id: 'af8b13ea-02a9-4e73-b8d9-58c8215757b9', email: 'test@test.com', login: '...' }
let token = await client.loginTenant('test@test.com', 'Password1')
Work with User
To work with users you need a tenant token. Field scope
is optional.
let user = await client.createUser({
email: 'test@test.com',
login: 'test@test.com',
password: 'Password1',
scope: 'admin',
sub: '123'
}, 'tenant-token'
)
// { id: '55096b7d-0f14-446a-b50d-ee6bc8431e39', email: 'test@test.com', login:... }
More details can be received in the tests.
Project setup
- Clone the repo
cd /path/to/repo
docker-compose build
- build development containersdocker-compose run --rm authclient sh -c "yarn"
Local testing
To run all tests just type docker-compose run --rm authclient sh -c "yarn test"
0.1.4
6 years ago