@ts-core/oauth 3.1.4 → 3.1.6

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,7 +3,7 @@ import { PopUpBase } from "./PopUpBase";
3
3
  export declare abstract class OAuthBase<T = any> extends PopUpBase<IOAuthDto> {
4
4
  protected applicationId: string;
5
5
  redirectUri: string;
6
- protected http: TransportHttp;
6
+ protected _http: TransportHttp;
7
7
  protected responseType: string;
8
8
  constructor(logger: ILogger, applicationId: string, window?: Window);
9
9
  protected getRedirectUri(): string;
@@ -17,6 +17,7 @@ export declare abstract class OAuthBase<T = any> extends PopUpBase<IOAuthDto> {
17
17
  getToken(): Promise<IOAuthDto>;
18
18
  parse(item: any): void;
19
19
  destroy(): void;
20
+ get http(): TransportHttp;
20
21
  get state(): string;
21
22
  }
22
23
  export interface IOAuthDto {
package/cjs/OAuthBase.js CHANGED
@@ -14,16 +14,16 @@ const common_1 = require("@ts-core/common");
14
14
  const _ = require("lodash");
15
15
  const rxjs_1 = require("rxjs");
16
16
  const PopUpBase_1 = require("./PopUpBase");
17
- const public_api_1 = require("./public-api");
17
+ const browser_1 = require("./external/browser");
18
18
  class OAuthBase extends PopUpBase_1.PopUpBase {
19
19
  constructor(logger, applicationId, window) {
20
20
  super(logger, window);
21
21
  this.applicationId = applicationId;
22
- this.http = new common_1.TransportHttp(logger, { method: 'get' });
22
+ this._http = new common_1.TransportHttp(logger, { method: 'get', timeout: common_1.DateUtil.MILLISECONDS_MINUTE });
23
23
  this.subject = new rxjs_1.Subject();
24
24
  this.params.set('state', common_1.RandomUtil.randomString());
25
25
  this.params.set('display', 'popup');
26
- (0, public_api_1.OAuthBrowserPropertiesSet)(this);
26
+ (0, browser_1.OAuthBrowserPropertiesSet)(this);
27
27
  }
28
28
  getRedirectUri() {
29
29
  return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.originUrl}/oauth`;
@@ -67,11 +67,14 @@ class OAuthBase extends PopUpBase_1.PopUpBase {
67
67
  return;
68
68
  }
69
69
  super.destroy();
70
- if (!_.isNil(this.http)) {
71
- this.http.destroy();
72
- this.http = null;
70
+ if (!_.isNil(this._http)) {
71
+ this._http.destroy();
72
+ this._http = null;
73
73
  }
74
74
  }
75
+ get http() {
76
+ return this._http;
77
+ }
75
78
  get state() {
76
79
  return !_.isNil(this.params) ? this.params.get('state') : null;
77
80
  }
@@ -1,2 +1,2 @@
1
- import { OAuthBase } from '../OAuthBase';
2
- export declare const OAuthBrowserPropertiesSet: (item: OAuthBase) => void;
1
+ import { PopUpBase } from '../PopUpBase';
2
+ export declare const OAuthBrowserPropertiesSet: <U>(item: PopUpBase<U>) => void;
@@ -2,6 +2,7 @@ import { GoUser } from './GoUser';
2
2
  import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
3
3
  import { ILogger } from '@ts-core/common';
4
4
  export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
5
+ personFields: string;
5
6
  constructor(logger: ILogger, applicationId: string, window?: Window);
6
7
  popUpUrl(): string;
7
8
  getProfile(token: string): Promise<T>;
package/cjs/go/GoAuth.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GoAuth = void 0;
13
+ const _ = require("lodash");
13
14
  const GoUser_1 = require("./GoUser");
14
15
  const OAuthBase_1 = require("../OAuthBase");
15
16
  class GoAuth extends OAuthBase_1.OAuthBase {
@@ -24,6 +25,9 @@ class GoAuth extends OAuthBase_1.OAuthBase {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  let item = new GoUser_1.GoUser();
26
27
  item.parse(yield this.http.call('https://www.googleapis.com/oauth2/v3/userinfo', { headers: { 'Authorization': `Bearer ${token}` } }));
28
+ if (!_.isEmpty(this.personFields)) {
29
+ item.parsePerson(yield this.http.call(`https://people.googleapis.com/v1/people/me`, { headers: { 'Authorization': `Bearer ${token}` }, data: { personFields: this.personFields } }));
30
+ }
27
31
  return item;
28
32
  });
29
33
  }
@@ -3,4 +3,5 @@ export declare class GoUser extends OAuthUser {
3
3
  givenName: string;
4
4
  familyName: string;
5
5
  parse(item: any): void;
6
+ parsePerson(item: any): void;
6
7
  }
package/cjs/go/GoUser.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GoUser = void 0;
4
4
  const OAuthUser_1 = require("../OAuthUser");
5
+ const _ = require("lodash");
5
6
  class GoUser extends OAuthUser_1.OAuthUser {
6
7
  parse(item) {
7
8
  this.id = item.sub;
@@ -12,5 +13,18 @@ class GoUser extends OAuthUser_1.OAuthUser {
12
13
  this.givenName = item.given_name;
13
14
  this.familyName = item.family_name;
14
15
  }
16
+ parsePerson(item) {
17
+ if (!_.isEmpty(item.genders)) {
18
+ this.isMale = _.first(item.genders).value === 'male';
19
+ }
20
+ if (!_.isEmpty(item.birthdays)) {
21
+ for (let value of item.birthdays) {
22
+ if (!_.isNil(value.date) && !_.isNil(value.date.year) && !_.isNil(value.date.month) && !_.isNil(value.date.day)) {
23
+ this.birthday = new Date(value.date.year, value.date.month - 1, value.date.day);
24
+ break;
25
+ }
26
+ }
27
+ }
28
+ }
15
29
  }
16
30
  exports.GoUser = GoUser;
@@ -3,7 +3,7 @@ import { PopUpBase } from "./PopUpBase";
3
3
  export declare abstract class OAuthBase<T = any> extends PopUpBase<IOAuthDto> {
4
4
  protected applicationId: string;
5
5
  redirectUri: string;
6
- protected http: TransportHttp;
6
+ protected _http: TransportHttp;
7
7
  protected responseType: string;
8
8
  constructor(logger: ILogger, applicationId: string, window?: Window);
9
9
  protected getRedirectUri(): string;
@@ -17,6 +17,7 @@ export declare abstract class OAuthBase<T = any> extends PopUpBase<IOAuthDto> {
17
17
  getToken(): Promise<IOAuthDto>;
18
18
  parse(item: any): void;
19
19
  destroy(): void;
20
+ get http(): TransportHttp;
20
21
  get state(): string;
21
22
  }
22
23
  export interface IOAuthDto {
package/esm/OAuthBase.js CHANGED
@@ -7,16 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { TransportHttp, RandomUtil, ExtendedError } from "@ts-core/common";
10
+ import { TransportHttp, RandomUtil, ExtendedError, DateUtil } from "@ts-core/common";
11
11
  import * as _ from 'lodash';
12
12
  import { Subject } from "rxjs";
13
13
  import { PopUpBase } from "./PopUpBase";
14
- import { OAuthBrowserPropertiesSet } from "./public-api";
14
+ import { OAuthBrowserPropertiesSet } from "./external/browser";
15
15
  export class OAuthBase extends PopUpBase {
16
16
  constructor(logger, applicationId, window) {
17
17
  super(logger, window);
18
18
  this.applicationId = applicationId;
19
- this.http = new TransportHttp(logger, { method: 'get' });
19
+ this._http = new TransportHttp(logger, { method: 'get', timeout: DateUtil.MILLISECONDS_MINUTE });
20
20
  this.subject = new Subject();
21
21
  this.params.set('state', RandomUtil.randomString());
22
22
  this.params.set('display', 'popup');
@@ -64,11 +64,14 @@ export class OAuthBase extends PopUpBase {
64
64
  return;
65
65
  }
66
66
  super.destroy();
67
- if (!_.isNil(this.http)) {
68
- this.http.destroy();
69
- this.http = null;
67
+ if (!_.isNil(this._http)) {
68
+ this._http.destroy();
69
+ this._http = null;
70
70
  }
71
71
  }
72
+ get http() {
73
+ return this._http;
74
+ }
72
75
  get state() {
73
76
  return !_.isNil(this.params) ? this.params.get('state') : null;
74
77
  }
@@ -1,2 +1,2 @@
1
- import { OAuthBase } from '../OAuthBase';
2
- export declare const OAuthBrowserPropertiesSet: (item: OAuthBase) => void;
1
+ import { PopUpBase } from '../PopUpBase';
2
+ export declare const OAuthBrowserPropertiesSet: <U>(item: PopUpBase<U>) => void;
@@ -2,6 +2,7 @@ import { GoUser } from './GoUser';
2
2
  import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
3
3
  import { ILogger } from '@ts-core/common';
4
4
  export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
5
+ personFields: string;
5
6
  constructor(logger: ILogger, applicationId: string, window?: Window);
6
7
  popUpUrl(): string;
7
8
  getProfile(token: string): Promise<T>;
package/esm/go/GoAuth.js CHANGED
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import * as _ from 'lodash';
10
11
  import { GoUser } from './GoUser';
11
12
  import { OAuthBase } from '../OAuthBase';
12
13
  export class GoAuth extends OAuthBase {
@@ -21,6 +22,9 @@ export class GoAuth extends OAuthBase {
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
23
  let item = new GoUser();
23
24
  item.parse(yield this.http.call('https://www.googleapis.com/oauth2/v3/userinfo', { headers: { 'Authorization': `Bearer ${token}` } }));
25
+ if (!_.isEmpty(this.personFields)) {
26
+ item.parsePerson(yield this.http.call(`https://people.googleapis.com/v1/people/me`, { headers: { 'Authorization': `Bearer ${token}` }, data: { personFields: this.personFields } }));
27
+ }
24
28
  return item;
25
29
  });
26
30
  }
@@ -3,4 +3,5 @@ export declare class GoUser extends OAuthUser {
3
3
  givenName: string;
4
4
  familyName: string;
5
5
  parse(item: any): void;
6
+ parsePerson(item: any): void;
6
7
  }
package/esm/go/GoUser.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { OAuthUser } from "../OAuthUser";
2
+ import * as _ from 'lodash';
2
3
  export class GoUser extends OAuthUser {
3
4
  parse(item) {
4
5
  this.id = item.sub;
@@ -9,4 +10,17 @@ export class GoUser extends OAuthUser {
9
10
  this.givenName = item.given_name;
10
11
  this.familyName = item.family_name;
11
12
  }
13
+ parsePerson(item) {
14
+ if (!_.isEmpty(item.genders)) {
15
+ this.isMale = _.first(item.genders).value === 'male';
16
+ }
17
+ if (!_.isEmpty(item.birthdays)) {
18
+ for (let value of item.birthdays) {
19
+ if (!_.isNil(value.date) && !_.isNil(value.date.year) && !_.isNil(value.date.month) && !_.isNil(value.date.day)) {
20
+ this.birthday = new Date(value.date.year, value.date.month - 1, value.date.day);
21
+ break;
22
+ }
23
+ }
24
+ }
25
+ }
12
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",