1 | ;
|
2 |
|
3 | const assumeRole = require('./lib/aws/assume-role.js');
|
4 | const loginCommon = require('./lib/common/login.js');
|
5 | const logoutCommon = require('./lib/common/logout.js');
|
6 | const tenant = require('./lib/common/tenant.js');
|
7 | const profile = require('./lib/auth0/profile.js');
|
8 |
|
9 | const privateVars = new WeakMap();
|
10 |
|
11 | /**
|
12 | * Class representing a Blink Mobile identity.
|
13 | */
|
14 | class BlinkMobileIdentity {
|
15 | /**
|
16 | * Create a Blink Mobile identity.
|
17 | * @param {String} clientName - The name of the client.
|
18 | */
|
19 | constructor (clientName) {
|
20 | privateVars.set(this, {
|
21 | clientName
|
22 | });
|
23 | }
|
24 |
|
25 | /**
|
26 | * Login to a client using a Blink Mobile identity.
|
27 | * @param {Object} options - The login options.
|
28 | * @returns {String} The JWT generated after a successful login.
|
29 | */
|
30 | login (options) {
|
31 | return loginCommon.login(privateVars.get(this).clientName, options);
|
32 | }
|
33 |
|
34 | /**
|
35 | * Logout of the client.
|
36 | */
|
37 | logout () {
|
38 | return logoutCommon.logout(privateVars.get(this).clientName);
|
39 | }
|
40 |
|
41 | /**
|
42 | * Get temporary AWS role's credentials.
|
43 | * @param {Object} Additional parameters to pass to the delegation endpoint.
|
44 | * @returns {Object} The AWS credentials.
|
45 | */
|
46 | assumeAWSRole (additionalParameters) {
|
47 | return assumeRole(privateVars.get(this).clientName, additionalParameters);
|
48 | }
|
49 |
|
50 | /**
|
51 | * Get the Auth0 profile for the current user.
|
52 | * @returns {Object} The Auth0 profile.
|
53 | */
|
54 | getProfile () {
|
55 | return profile.getByClient(privateVars.get(this).clientName);
|
56 | }
|
57 |
|
58 | /**
|
59 | * Show the currently set and available tenants.
|
60 | * @param {String} clientName - The name of a Client.
|
61 | */
|
62 | getTenants () {
|
63 | return tenant.get();
|
64 | }
|
65 |
|
66 | /**
|
67 | * Change the currently set tenant, will then show the currently set and available tenants.
|
68 | * @param {String} tenantName - The name of a tenant to set.
|
69 | */
|
70 | setTenant (tenantName) {
|
71 | return tenant.set(tenantName);
|
72 | }
|
73 |
|
74 | /**
|
75 | * Remove a tenant from the available tenants, will then show the currently set and available tenants.
|
76 | * @param {String} tenantName - The name of a tenant to remove.
|
77 | */
|
78 | removeTenant (tenantName) {
|
79 | return tenant.remove(tenantName);
|
80 | }
|
81 | }
|
82 |
|
83 | module.exports = BlinkMobileIdentity;
|