@gudhub/core 1.1.90 → 1.1.91

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.
@@ -10,6 +10,12 @@ export class Auth {
10
10
  return user;
11
11
  }
12
12
 
13
+ async loginWithToken(token) {
14
+ const user = await this.loginWithTokenApi(token);
15
+ this.storage.updateUser(user);
16
+ return user;
17
+ }
18
+
13
19
  async logout(token) {
14
20
  const response = await this.logoutApi(token);
15
21
  return response;
@@ -58,6 +64,18 @@ export class Auth {
58
64
  }
59
65
  }
60
66
 
67
+ async loginWithTokenApi(token) {
68
+ try {
69
+ const user = await this.req.axiosRequest({
70
+ method: 'POST',
71
+ url: `${this.req.root}/auth/login?accesstoken=${token}`
72
+ });
73
+ return user;
74
+ } catch (error) {
75
+ console.log(error);
76
+ }
77
+ }
78
+
61
79
  async updateTokenApi(auth_key) {
62
80
  try {
63
81
  const user = await this.req.axiosRequest({
@@ -1,4 +1,4 @@
1
- import should from "should";
1
+
2
2
  import {GudHub} from './../gudhub.js';
3
3
 
4
4
  describe("AUTHORIZATION", async function() {
@@ -22,6 +22,16 @@ describe("AUTHORIZATION", async function() {
22
22
  user.fullname.should.equal('Vasya Pupkin');
23
23
  })
24
24
 
25
+ it("Authentication with access token", async function () {
26
+ const gudhub = new GudHub();
27
+
28
+ const token = 'accesstoken';
29
+
30
+ const user = await gudhub.loginWithToken(token);
31
+
32
+ user.hasOwnProperty('fullname').should.equal(true);
33
+ })
34
+
25
35
  it("Signing up user", async function () {
26
36
  const gudhub = new GudHub();
27
37
  let credentials = {
package/GUDHUB/gudhub.js CHANGED
@@ -31,7 +31,9 @@ export class GudHub {
31
31
  swLink: "",
32
32
  async_modules_path,
33
33
  file_server_url,
34
- automation_modules_path
34
+ automation_modules_path,
35
+ accesstoken: this.accesstoken,
36
+ expirydate: this.expirydate
35
37
  }
36
38
  ) {
37
39
  this.config = options;
@@ -44,7 +46,15 @@ export class GudHub {
44
46
  this.auth = new Auth(this.req, this.storage);
45
47
  this.sharing = new Sharing(this, this.req);
46
48
  this.groupSharing = new GroupSharing(this, this.req, this.pipeService);
47
- if (authKey) this.storage.setUser({ auth_key: authKey });
49
+
50
+ // Login with access token - pass to setUser access token and after it user can make requests with access token
51
+ // This method created for optimize GudHub initialization without auth key
52
+ if (authKey) {
53
+ this.storage.setUser({ auth_key: authKey })
54
+ } else if(options.accesstoken && options.expirydate) {
55
+ this.storage.setUser({accesstoken: options.accesstoken, expirydate: options.expirydate})
56
+ }
57
+
48
58
  this.req.init(this.auth.getToken.bind(this.auth));
49
59
 
50
60
  this.ws = new WebSocketApi(options.wss_url, this.auth);
@@ -442,6 +452,10 @@ export class GudHub {
442
452
  return this.auth.login(data);
443
453
  }
444
454
 
455
+ loginWithToken(token) {
456
+ return this.auth.loginWithToken(token);
457
+ }
458
+
445
459
  logout(token) {
446
460
  this.appProcessor.clearAppProcessor();
447
461
  return this.auth.logout(token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.90",
3
+ "version": "1.1.91",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {