UNPKG

2.65 kBMarkdownView Raw
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
3Provides easy management of authenication for our CLI via a single identity.
4
5## Getting Started
6
7```sh
8npm install @blinkmobile/bm-identity --save
9```
10
11```js
12const pkg = require('./package.json');
13const BlinkMobileIdentity = require('@blinkmobile/bm-identity');
14const blinkMobileIdentity = new BlinkMobileIdentity(pkg.name);
15```
16
17## Usage
18
19### Login
20
21If 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
24login (options: LoginOptions) => Promise{String}
25```
26
27```js
28interface 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
37blinkMobileIdentity.login()
38 .then(jwt => {
39 // Use jwt access token.
40 });
41```
42
43### Logout
44
45```js
46logout () => Promise
47```
48
49```js
50blinkMobileIdentity.logout();
51```
52
53### Assume AWS Role
54
55```js
56assumeAWSRole (additionalParameters: Object) => Promise{AssumedRoleCredentials}
57```
58
59```js
60interface AssumedRoleCredentials {
61 accessKeyId : String,
62 secretAccessKey : String,
63 sessionToken : String
64}
65```
66
67```js
68blinkMobileIdentity.assumeAWSRole()
69 .then(credentials => {
70 // Use AWS credentials
71 });
72```
73
74### Get Profile
75
76```js
77getProfile () => Promise{Auth0Profile}
78```
79
80```js
81blinkMobileIdentity.getProfile()
82 .then(profile => {
83 // Use Auth0 profile
84 });
85```
86
87See [Auth0 Profile Structure](https://auth0.com/docs/user-profile/user-profile-structure) for available properties.
88
89### Manage Tenants
90
91Get and set the current tenant. Also get and remove list of previously used tenants.
92
93```js
94getTenants () => Promise{Tenants}
95```
96
97```js
98setTenant (tenantName: String) => Promise{Tenants}
99```
100
101```js
102removeTenant (tenantName: String) => Promise{Tenants}
103```
104
105```js
106interface Tenants {
107 current : String,
108 previous : Array{String}
109}
110```
111
112```js
113blinkMobileIdentity.getTenants()
114 .then(tenants => {
115 // Use tenants
116 });
117
118blinkMobileIdentity.setTenant('TenantName')
119 .then(tenants => {
120 // Tenant was set
121 });
122
123blinkMobileIdentity.removeTenant('TenantName')
124 .then(tenants => {
125 // Tenant was removed
126 });
127```