1 | # bm-identity.js [![npm](https://img.shields.io/npm/v/@blinkmobile/bm-identity.svg?maxAge=2592000)](https://www.npmjs.com/package/@blinkmobile/bm-identity) [![Travis CI Status](https://travis-ci.org/blinkmobile/bm-identity.js.svg?branch=master)](https://travis-ci.org/blinkmobile/bm-identity.js)
|
2 |
|
3 | Provides easy management of authenication for our CLI via a single identity.
|
4 |
|
5 | ## Getting Started
|
6 |
|
7 | ```sh
|
8 | npm install @blinkmobile/bm-identity --save
|
9 | ```
|
10 |
|
11 | ```js
|
12 | const pkg = require('./package.json');
|
13 | const BlinkMobileIdentity = require('@blinkmobile/bm-identity');
|
14 | const blinkMobileIdentity = new BlinkMobileIdentity(pkg.name);
|
15 | ```
|
16 |
|
17 | ## Usage
|
18 |
|
19 | ### Login
|
20 |
|
21 | If no LoginOptions are passed, a browser based login process will start. This is how users can login using a social account e.g. Google.
|
22 |
|
23 | ```js
|
24 | login (options: LoginOptions) => Promise{String}
|
25 | ```
|
26 |
|
27 | ```js
|
28 | interface LoginOptions {
|
29 | username? : String|Boolean, // Can also pass true, and username will be prompted for
|
30 | password? : String, // Will be prompted for password if username is truthy
|
31 | email? : String|Boolean, // Can also pass true to be prompted for email address
|
32 | sms? : String|Boolean, // Can also pass true to be prompted for phone number
|
33 | }
|
34 | ```
|
35 |
|
36 | ```js
|
37 | blinkMobileIdentity.login()
|
38 | .then(jwt => {
|
39 | // Use jwt access token.
|
40 | });
|
41 | ```
|
42 |
|
43 | ### Logout
|
44 |
|
45 | ```js
|
46 | logout () => Promise
|
47 | ```
|
48 |
|
49 | ```js
|
50 | blinkMobileIdentity.logout();
|
51 | ```
|
52 |
|
53 | ### Assume AWS Role
|
54 |
|
55 | ```js
|
56 | assumeAWSRole (additionalParameters: Object) => Promise{AssumedRoleCredentials}
|
57 | ```
|
58 |
|
59 | ```js
|
60 | interface AssumedRoleCredentials {
|
61 | accessKeyId : String,
|
62 | secretAccessKey : String,
|
63 | sessionToken : String
|
64 | }
|
65 | ```
|
66 |
|
67 | ```js
|
68 | blinkMobileIdentity.assumeAWSRole()
|
69 | .then(credentials => {
|
70 | // Use AWS credentials
|
71 | });
|
72 | ```
|
73 |
|
74 | ### Get Profile
|
75 |
|
76 | ```js
|
77 | getProfile () => Promise{Auth0Profile}
|
78 | ```
|
79 |
|
80 | ```js
|
81 | blinkMobileIdentity.getProfile()
|
82 | .then(profile => {
|
83 | // Use Auth0 profile
|
84 | });
|
85 | ```
|
86 |
|
87 | See [Auth0 Profile Structure](https://auth0.com/docs/user-profile/user-profile-structure) for available properties.
|
88 |
|
89 | ### Manage Tenants
|
90 |
|
91 | Get and set the current tenant. Also get and remove list of previously used tenants.
|
92 |
|
93 | ```js
|
94 | getTenants () => Promise{Tenants}
|
95 | ```
|
96 |
|
97 | ```js
|
98 | setTenant (tenantName: String) => Promise{Tenants}
|
99 | ```
|
100 |
|
101 | ```js
|
102 | removeTenant (tenantName: String) => Promise{Tenants}
|
103 | ```
|
104 |
|
105 | ```js
|
106 | interface Tenants {
|
107 | current : String,
|
108 | previous : Array{String}
|
109 | }
|
110 | ```
|
111 |
|
112 | ```js
|
113 | blinkMobileIdentity.getTenants()
|
114 | .then(tenants => {
|
115 | // Use tenants
|
116 | });
|
117 |
|
118 | blinkMobileIdentity.setTenant('TenantName')
|
119 | .then(tenants => {
|
120 | // Tenant was set
|
121 | });
|
122 |
|
123 | blinkMobileIdentity.removeTenant('TenantName')
|
124 | .then(tenants => {
|
125 | // Tenant was removed
|
126 | });
|
127 | ```
|