@leapdev/auth-agent 2.0.0-alpha.1 → 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +307 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,312 @@
1
- # auth-agent
1
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ### Table of Contents
4
4
 
5
- ## Building
5
+ - [init][1]
6
+ - [Parameters][2]
7
+ - [login][3]
8
+ - [logout][4]
9
+ - [changePassword][5]
10
+ - [Parameters][6]
11
+ - [registerHook][7]
12
+ - [Parameters][8]
13
+ - [getAccessToken][9]
14
+ - [Parameters][10]
15
+ - [getDecodedAccessToken][11]
16
+ - [userInfo][12]
17
+ - [getCloudProviderToken][13]
18
+ - [Parameters][14]
19
+ - [cloudProviderUserInfo][15]
20
+ - [getAdminConsent][16]
21
+ - [Parameters][17]
22
+ - [revokeAdminConsent][18]
23
+ - [statusAdminConsent][19]
24
+ - [getLinkMap][20]
25
+ - [setLinkMap][21]
26
+ - [Parameters][22]
27
+ - [linkUser][23]
28
+ - [Parameters][24]
29
+ - [unlinkUser][25]
30
+ - [Parameters][26]
31
+ - [cloudProviderReauthenticate][27]
32
+ - [Parameters][28]
33
+ - [cloudProviderUpdate][29]
34
+ - [Parameters][30]
35
+ - [registerEventListener][31]
36
+ - [Parameters][32]
37
+ - [authoriseSupport][33]
38
+ - [Parameters][34]
6
39
 
7
- Run `nx build auth-agent` to build the library.
40
+ ## init
8
41
 
9
- ## Running unit tests
42
+ Initialize the Auth Agent. This function needs to be called at the very beginning of the loading of the app.
43
+ If the query contains parameters "code" and "state", the Auth Agent will exchange the auth code for an access_token and store the access_token in memory for later use.
44
+
45
+ ### Parameters
46
+
47
+ - `authHost` **[string][36]** : LEAP Auth url (required)
48
+ - `clientId` **[string][36]** : LEAP Auth client id (required)
49
+ - `scopes` **[Array<string>][36]** : a list of scopes for the access_token (required)
50
+ - `autoLogin` **[boolean][37]** : If true, the login function is called once the Auth Agent is initialized (optional, default `true`)
51
+ - `autoLogout` **[boolean][37]** : If true, the user will be automatically logged out after a configurable time interval if no activity detected (optional, default `true`)
52
+ - `idleTimeoutInMinutes` **[number][37]** : In minutes, the time interval after which the user is automatically logged out if no activity detected (optional, default `30`)
53
+ - `uniqueSession` **[boolean][37]** : If true, the same user can't have more than one active session for the same app, based on authHost and clientId (optional, default `true`)
54
+ - `hooks` **[object][38]** : callback functions(optional, default: no hooks)
55
+ * afterLogin: Callback function that take the access_token, executed after login.
56
+ * beforeLogout: Callback function executed before logout.
57
+
58
+
59
+ Returns **[Promise][39]** Nothing if autoLogin is turned off, the access_token if autoLogin is turned on
60
+
61
+ ## login
62
+
63
+ Login function using PKCE flow.
64
+ Executes hook afterLogin if any.
65
+
66
+ Returns **[Promise][39]** The access_token
67
+
68
+ ## logout
69
+
70
+ Executes hook beforeLogout if any.
71
+
72
+ ## changePassword
73
+
74
+ Change Password function.
75
+
76
+ ### Parameters
77
+
78
+ - `redirectUrl` **[string][36]** Url to redirect the browser to after password changed when newWindow = false (current URL by default) (optional, default `currentUrl`)
79
+ - `newWindow` **[boolean][37]** If newWindow = false, changingPassword process will be executed in the same window. Once this done, user would be force to logout and the browser will be redirected to the redirectUrl (current url by default).
80
+ If newWindow = true, changingPassword process will be executed in a new window. Once this done, user would be force to logout by pubnub presence message
81
+ 1) if there is callback fn, the dedicated window will be closed and the callback will be executed.
82
+ 2) if there is no callback fn, the dedicated window will stay open and user would be navigated to a changePasswordSuccess confirm page (optional, default `false`)
83
+ - `callback` **[function][38]** The callback function to be executed after changingPassword is done when newWindow = true
84
+
85
+ ## registerHook
86
+
87
+ Allows to register hook on the fly.
88
+
89
+ ### Parameters
90
+
91
+ - `name` **[string][36]** The name of the hook : afterLogin or beforeLogout
92
+ - `callback` **[function][38]** The callback
93
+
94
+ ## getAccessToken
95
+
96
+ Allows to retrieve the encoded access_token.
97
+ If refresh is true, make a request to Leap Auth to get a new access token, and return a promise.
98
+ Otherwise, get the access token stored by JSO and return a string
99
+
100
+ ### Parameters
101
+
102
+ - `refresh` **[boolean][37]** Force refresh token (optional, default `false`)
103
+
104
+ Returns **[Promise][39]** The access_token (promise if refresh is true, otherwise string)
105
+
106
+ ## getDecodedAccessToken
107
+
108
+ Allows to retrieve the decoded access_token stored by JSO
109
+
110
+ Returns **[object][35]** The decoded access_token
111
+
112
+ ## userInfo
113
+
114
+ Returns user info, including external user info if the user is linked to a cloud provider account.
115
+
116
+ Returns **[object][35]** user info
117
+
118
+ ## getCloudProviderToken
119
+
120
+ Get a cloud proiver token for the current user.
121
+ Get the token by jti if the paramter exists.
122
+
123
+ ### Parameters
124
+
125
+ - `jti` **[string][36]** The token id (optional)
126
+
127
+ Returns **[Promise][39]** The token
128
+
129
+ ## cloudProviderUserInfo
130
+
131
+ Returns the cloud provider info related to the current user.
132
+
133
+ Returns **[Promise][39]** The info
134
+
135
+ ## getAdminConsent
136
+
137
+ Redirects the browser to the admin consent page of the current user's cloud provider.
138
+ Then, the browser is redirected to the redirectUrl.
139
+
140
+ ### Parameters
141
+
142
+ - `domain` **[string][36]** The cloud provider domain of the firm (optional)
143
+ - `redirectUrl` **[string][36]** Url to redirect the browser to after getting the admin consent when newWindow is not true (current URL by default) (optional, default `currentUrl`)
144
+ - `newWindow` **[boolean][37]** If true, admin consent process will be executed in a new window. Once done, the dedicated window will be closed and the callback will be executed. If false, admin consent process will be executed in the same window and once done, the browser will be redirected to the redirectUrl. (optional, default `false`)
145
+ - `callback` **[function][38]** The callback to execute after admin consent is given when newWindow = true
146
+
147
+ ## revokeAdminConsent
148
+
149
+ Revoke admin consent.
150
+
151
+ Returns **[Promise][39]**
152
+
153
+ ## statusAdminConsent
154
+
155
+ Returns the status of admin consent for the firm
156
+
157
+ Returns **[Promise][39]** true if admin consent have been given, otherwise false
158
+
159
+ ## getLinkMap
160
+
161
+ Returns the list of all the users of the tenant, each one mapped with it's internal linked user if any.
162
+
163
+ Returns **[Promise][39]** The map
164
+
165
+ ## setLinkMap
166
+
167
+ Allows to save the mapping between users of the tenant and internal linked users.
168
+
169
+ ### Parameters
170
+
171
+ - `linkmap` **[array][40]** The map
172
+
173
+ Returns **[Promise][39]**
174
+
175
+ ## linkUser
176
+
177
+ Link current user to a cloud provider account.
178
+
179
+ ### Parameters
180
+
181
+ - `redirectUrl` **[string][36]** Url to redirect the browser to after linking the user when newWindow is not true (current URL by default) (optional, default `currentUrl`)
182
+ - `newWindow` **[boolean][37]** If true, linking process will be executed in a new window. Once done, the dedicated window will be closed and the callback will be executed. If false, linking process will be executed in the same window and once done, the browser will be redirected to the redirectUrl. (optional, default `false`)
183
+ - `callback` **[function][38]** The callback to execute after linking is done when newWindow = true
184
+
185
+ ## unlinkUser
186
+
187
+ Unlink current user from cloud provider account.
188
+
189
+ ### Parameters
190
+
191
+ - `redirectUrl` **[string][36]** Url to redirect the browser to after unlinking the user when newWindow is not true (current URL by default) (optional, default `currentUrl`)
192
+ - `newWindow` **[boolean][37]** If true, unlinking process will be executed in a new window. Once done, the dedicated window will be closed and the callback will be executed. If false, unlinking process will be executed in the same window and once done, the browser will be redirected to the redirectUrl. (optional, default `false`)
193
+ - `callback` **[function][38]** The callback to execute after unlinking is done when newWindow = true
194
+
195
+ ## cloudProviderReauthenticate
196
+
197
+ Allows to reauthenticate the user against it's cloud provider to renew the access token
198
+
199
+ ### Parameters
200
+
201
+ - `nonce` **[string][36]** A nonce generated by Leap Auth, required but can be null (required)
202
+ - `redirectUrl` **[string][36]** Url to redirect the browser to after reauthentication when newWindow is not true (current URL by default) (optional, default `currentUrl`)
203
+ - `newWindow` **[boolean][37]** If true, re-authentication process will be executed in a new window. Once done, the dedicated window will be closed and the callback will be executed. If false, re-authentication process will be executed in the same window and once done, the browser will be redirected to the redirectUrl. (optional, default `false`)
204
+ - `callback` **[function][38]** The callback to execute after re-authentication is done when newWindow = true
205
+
206
+ ## cloudProviderUpdate
207
+
208
+ Updates the firm's cloud provider
209
+
210
+ ### Parameters
211
+
212
+ - `cloudProviderId` **[string][36]** "microsoft", "google" (required)
213
+
214
+ ## registerEventListener
215
+
216
+ Allows to register a callback to execute when receiving a user event for the topic and message type passed as paramters.
217
+
218
+ ### Parameters
219
+
220
+ - `topic` **[string][36]** The topic (required)
221
+ - `messageType` **[string][36]** The type of message (required)
222
+ - `callback` **[function][38]** The callback to execute when receiving the message (required)
223
+
224
+ ## authoriseSupport
225
+
226
+ Allows to authorise a support request from a support agent.
227
+
228
+ ### Parameters
229
+
230
+ - `code` **[string][36]** The code of the support request received (required)
231
+ - `duration` **[string][36]** The duration of the support request can be modified by the user. It has to be in momentjs format (optional)
232
+
233
+ [1]: #init
234
+
235
+ [2]: #parameters
236
+
237
+ [3]: #login
238
+
239
+ [4]: #logout
240
+
241
+ [5]: #changepassword
242
+
243
+ [6]: #parameters-1
244
+
245
+ [7]: #registerhook
246
+
247
+ [8]: #parameters-2
248
+
249
+ [9]: #getaccesstoken
250
+
251
+ [10]: #parameters-3
252
+
253
+ [11]: #getdecodedaccesstoken
254
+
255
+ [12]: #userinfo
256
+
257
+ [13]: #getcloudprovidertoken
258
+
259
+ [14]: #parameters-4
260
+
261
+ [15]: #cloudprovideruserinfo
262
+
263
+ [16]: #getadminconsent
264
+
265
+ [17]: #parameters-5
266
+
267
+ [18]: #revokeadminconsent
268
+
269
+ [19]: #statusadminconsent
270
+
271
+ [20]: #getlinkmap
272
+
273
+ [21]: #setlinkmap
274
+
275
+ [22]: #parameters-6
276
+
277
+ [23]: #linkuser
278
+
279
+ [24]: #parameters-7
280
+
281
+ [25]: #unlinkuser
282
+
283
+ [26]: #parameters-8
284
+
285
+ [27]: #cloudproviderreauthenticate
286
+
287
+ [28]: #parameters-9
288
+
289
+ [29]: #cloudproviderupdate
290
+
291
+ [30]: #parameters-10
292
+
293
+ [31]: #registereventlistener
294
+
295
+ [32]: #parameters-11
296
+
297
+ [33]: #authorisesupport
298
+
299
+ [34]: #parameters-12
300
+
301
+ [35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
302
+
303
+ [36]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
304
+
305
+ [37]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
306
+
307
+ [38]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
308
+
309
+ [39]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
310
+
311
+ [40]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
10
312
 
11
- Run `nx test auth-agent` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapdev/auth-agent",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.2",
4
4
  "type": "commonjs",
5
5
  "description": "LEAP Auth Agent",
6
6
  "license": "LEAP Legal Software, PTY LTD",