@ts-core/oauth 3.0.13 → 3.0.15

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.
@@ -3,12 +3,14 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
3
3
  protected applicationId: string;
4
4
  protected window?: Window;
5
5
  static ERROR_WINDOW_CLOSED: string;
6
+ popUpWidth: number;
7
+ popUpHeight: number;
8
+ popUpTarget: string;
9
+ redirectUri: string;
6
10
  protected http: TransportHttp;
7
11
  protected timer: any;
8
12
  protected popUp: Window;
9
13
  protected promise: PromiseHandler<IOAuthDto>;
10
- protected popUpWidth: number;
11
- protected popUpHeight: number;
12
14
  protected responseType: string;
13
15
  protected _urlParams: Map<string, string>;
14
16
  constructor(logger: ILogger, applicationId: string, window?: Window);
@@ -17,9 +19,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
17
19
  protected checkPopUp: () => void;
18
20
  protected getUrlParams(): URLSearchParams;
19
21
  protected abstract getUrl(): string;
20
- protected messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
21
- protected get redirectUri(): string;
22
- protected get originUrl(): string;
22
+ messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
23
+ protected getOriginUrl(): string;
24
+ protected getRedirectUri(): string;
23
25
  abstract getProfile(token: string, ...params: any[]): Promise<T>;
24
26
  abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
25
27
  getCode(): Promise<IOAuthDto>;
package/cjs/OAuthBase.js CHANGED
@@ -19,6 +19,7 @@ class OAuthBase extends common_1.LoggerWrapper {
19
19
  this.window = window;
20
20
  this.popUpWidth = 430;
21
21
  this.popUpHeight = 520;
22
+ this.popUpTarget = '_blank';
22
23
  this.checkPopUp = () => {
23
24
  if (_.isNil(this.popUp) || this.popUp.closed) {
24
25
  this.close();
@@ -26,11 +27,11 @@ class OAuthBase extends common_1.LoggerWrapper {
26
27
  };
27
28
  this.messageHandler = (event) => {
28
29
  let data = event.data;
29
- if (event.origin !== this.originUrl || !_.isObject(data)) {
30
+ if (event.origin !== this.getOriginUrl() || !_.isObject(data)) {
30
31
  return;
31
32
  }
32
33
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
33
- this.promise.resolve({ redirectUri: this.redirectUri, codeOrToken: data.oAuthCodeOrToken });
34
+ this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
34
35
  }
35
36
  if (!_.isEmpty(data.oAuthError)) {
36
37
  this.promise.reject(data.oAuthError);
@@ -62,24 +63,24 @@ class OAuthBase extends common_1.LoggerWrapper {
62
63
  let window = this.window;
63
64
  let top = (window.screen.height - this.popUpHeight) / 2;
64
65
  let left = (window.screen.width - this.popUpWidth) / 2;
65
- let item = window.open(this.getUrl(), '_blank', `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
66
+ let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
66
67
  item.focus();
67
68
  return item;
68
69
  }
69
70
  getUrlParams() {
70
71
  let item = new URLSearchParams();
71
72
  item.append('client_id', this.applicationId);
72
- item.append('redirect_uri', this.redirectUri);
73
+ item.append('redirect_uri', this.getRedirectUri());
73
74
  item.append('response_type', this.responseType);
74
75
  this.urlParams.forEach((value, key) => item.append(key, value));
75
76
  return item;
76
77
  }
77
- get redirectUri() {
78
- return `${this.originUrl}/oauth`;
79
- }
80
- get originUrl() {
78
+ getOriginUrl() {
81
79
  return this.window.location.origin;
82
80
  }
81
+ getRedirectUri() {
82
+ return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
83
+ }
83
84
  getCode() {
84
85
  return __awaiter(this, void 0, void 0, function* () {
85
86
  this.responseType = 'code';
@@ -3,12 +3,14 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
3
3
  protected applicationId: string;
4
4
  protected window?: Window;
5
5
  static ERROR_WINDOW_CLOSED: string;
6
+ popUpWidth: number;
7
+ popUpHeight: number;
8
+ popUpTarget: string;
9
+ redirectUri: string;
6
10
  protected http: TransportHttp;
7
11
  protected timer: any;
8
12
  protected popUp: Window;
9
13
  protected promise: PromiseHandler<IOAuthDto>;
10
- protected popUpWidth: number;
11
- protected popUpHeight: number;
12
14
  protected responseType: string;
13
15
  protected _urlParams: Map<string, string>;
14
16
  constructor(logger: ILogger, applicationId: string, window?: Window);
@@ -17,9 +19,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
17
19
  protected checkPopUp: () => void;
18
20
  protected getUrlParams(): URLSearchParams;
19
21
  protected abstract getUrl(): string;
20
- protected messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
21
- protected get redirectUri(): string;
22
- protected get originUrl(): string;
22
+ messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
23
+ protected getOriginUrl(): string;
24
+ protected getRedirectUri(): string;
23
25
  abstract getProfile(token: string, ...params: any[]): Promise<T>;
24
26
  abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
25
27
  getCode(): Promise<IOAuthDto>;
package/esm/OAuthBase.js CHANGED
@@ -16,6 +16,7 @@ export class OAuthBase extends LoggerWrapper {
16
16
  this.window = window;
17
17
  this.popUpWidth = 430;
18
18
  this.popUpHeight = 520;
19
+ this.popUpTarget = '_blank';
19
20
  this.checkPopUp = () => {
20
21
  if (_.isNil(this.popUp) || this.popUp.closed) {
21
22
  this.close();
@@ -23,11 +24,11 @@ export class OAuthBase extends LoggerWrapper {
23
24
  };
24
25
  this.messageHandler = (event) => {
25
26
  let data = event.data;
26
- if (event.origin !== this.originUrl || !_.isObject(data)) {
27
+ if (event.origin !== this.getOriginUrl() || !_.isObject(data)) {
27
28
  return;
28
29
  }
29
30
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
30
- this.promise.resolve({ redirectUri: this.redirectUri, codeOrToken: data.oAuthCodeOrToken });
31
+ this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
31
32
  }
32
33
  if (!_.isEmpty(data.oAuthError)) {
33
34
  this.promise.reject(data.oAuthError);
@@ -59,24 +60,24 @@ export class OAuthBase extends LoggerWrapper {
59
60
  let window = this.window;
60
61
  let top = (window.screen.height - this.popUpHeight) / 2;
61
62
  let left = (window.screen.width - this.popUpWidth) / 2;
62
- let item = window.open(this.getUrl(), '_blank', `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
63
+ let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
63
64
  item.focus();
64
65
  return item;
65
66
  }
66
67
  getUrlParams() {
67
68
  let item = new URLSearchParams();
68
69
  item.append('client_id', this.applicationId);
69
- item.append('redirect_uri', this.redirectUri);
70
+ item.append('redirect_uri', this.getRedirectUri());
70
71
  item.append('response_type', this.responseType);
71
72
  this.urlParams.forEach((value, key) => item.append(key, value));
72
73
  return item;
73
74
  }
74
- get redirectUri() {
75
- return `${this.originUrl}/oauth`;
76
- }
77
- get originUrl() {
75
+ getOriginUrl() {
78
76
  return this.window.location.origin;
79
77
  }
78
+ getRedirectUri() {
79
+ return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
80
+ }
80
81
  getCode() {
81
82
  return __awaiter(this, void 0, void 0, function* () {
82
83
  this.responseType = 'code';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",