@aptana/multichannel-common 2.9.15 → 2.9.17

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.
@@ -14,14 +14,20 @@ export declare class TokenGuard implements Guard {
14
14
  * The currently authenticated user.
15
15
  */
16
16
  private _user;
17
+ /**
18
+ * Skip userKey & userToken authentication
19
+ */
20
+ private _skipUserKeyAuth;
17
21
  /**
18
22
  * Create a new authtentication guard.
19
23
  */
20
- constructor(provider: UserProvider, req: any);
24
+ constructor(provider: UserProvider, req: any, options?: {
25
+ skipUserKeyAuth?: boolean;
26
+ });
21
27
  /**
22
28
  * Determine if the current user is authenticated. If not, throw an error.
23
29
  */
24
- authenticate(): Promise<Authenticable>;
30
+ authenticate(): Promise<Authenticable | undefined>;
25
31
  check(): Promise<boolean>;
26
32
  guest(): Promise<boolean>;
27
33
  setUser(user: Authenticable): Promise<void>;
@@ -18,22 +18,34 @@ class TokenGuard {
18
18
  * The currently authenticated user.
19
19
  */
20
20
  _user;
21
+ /**
22
+ * Skip userKey & userToken authentication
23
+ */
24
+ _skipUserKeyAuth;
21
25
  /**
22
26
  * Create a new authtentication guard.
23
27
  */
24
- constructor(provider, req) {
28
+ constructor(provider, req, options) {
25
29
  this._provider = provider;
26
30
  this._req = req;
31
+ this._skipUserKeyAuth = options?.skipUserKeyAuth ?? false;
27
32
  }
28
33
  /**
29
34
  * Determine if the current user is authenticated. If not, throw an error.
30
35
  */
31
36
  async authenticate() {
32
- const user = await this.user();
33
- if (user) {
34
- return user;
37
+ try {
38
+ const user = await this.user();
39
+ if (user) {
40
+ return user;
41
+ }
42
+ }
43
+ catch (error) {
44
+ if (error && error.statusCode) {
45
+ throw error;
46
+ }
47
+ throw new WrongCredentialsError_1.default();
35
48
  }
36
- throw new WrongCredentialsError_1.default();
37
49
  }
38
50
  async check() {
39
51
  return !!(await this.user());
@@ -54,7 +66,8 @@ class TokenGuard {
54
66
  let user = null;
55
67
  let token = this.getTokenFromRequest();
56
68
  let { userKey, userToken } = this.getUserKeyTokenFromRequest();
57
- if (userKey && userToken) {
69
+ // Skip userKey auth if configured
70
+ if (!this._skipUserKeyAuth && userKey && userToken) {
58
71
  user = await this._provider.getByUserKeyAndUserToken(userKey, userToken);
59
72
  }
60
73
  else if (token) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptana/multichannel-common",
3
- "version": "2.9.15",
3
+ "version": "2.9.17",
4
4
  "license": "MIT",
5
5
  "description": "",
6
6
  "keywords": [