@ts-core/oauth 3.0.7 → 3.0.8

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.
@@ -0,0 +1,6 @@
1
+ import { IOAuthPopUpDto } from './OAuthBase';
2
+ export declare class OAuthParser {
3
+ names: Array<string>;
4
+ errors: Array<string>;
5
+ parse(params: any, fragment: string): Promise<IOAuthPopUpDto>;
6
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OAuthParser = void 0;
13
+ const _ = require("lodash");
14
+ class OAuthParser {
15
+ constructor() {
16
+ this.names = ['code', 'access_token'];
17
+ this.errors = ['error_description', 'error'];
18
+ }
19
+ parse(params, fragment) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ let item = new URLSearchParams();
22
+ _.forIn(params, (value, key) => item.append(key, value));
23
+ new URLSearchParams(fragment).forEach((value, key) => item.append(key, value));
24
+ let oAuthError = null;
25
+ let oAuthCodeOrToken = null;
26
+ item.forEach((value, key) => {
27
+ if (this.names.includes(key)) {
28
+ oAuthCodeOrToken = value;
29
+ }
30
+ else if (this.errors.includes(key)) {
31
+ oAuthError = value;
32
+ }
33
+ if (!_.isEmpty(oAuthCodeOrToken) || !_.isEmpty(oAuthError)) {
34
+ return { oAuthCodeOrToken, oAuthError };
35
+ }
36
+ });
37
+ return null;
38
+ });
39
+ }
40
+ }
41
+ exports.OAuthParser = OAuthParser;
@@ -1,5 +1,6 @@
1
1
  export * from './OAuthBase';
2
2
  export * from './OAuthUser';
3
+ export * from './OAuthParser';
3
4
  export * from './go/GoUser';
4
5
  export * from './go/GoAuth';
5
6
  export * from './vk/VkUser';
package/cjs/public-api.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./OAuthBase"), exports);
18
18
  __exportStar(require("./OAuthUser"), exports);
19
+ __exportStar(require("./OAuthParser"), exports);
19
20
  __exportStar(require("./go/GoUser"), exports);
20
21
  __exportStar(require("./go/GoAuth"), exports);
21
22
  __exportStar(require("./vk/VkUser"), exports);
package/cjs/vk/VkAuth.js CHANGED
@@ -18,7 +18,7 @@ class VkAuth extends OAuthBase_1.OAuthBase {
18
18
  constructor(logger, applicationId, window) {
19
19
  super(logger, applicationId, window);
20
20
  this.v = '5.131';
21
- this.urlParams.set('scope', 'status');
21
+ this.urlParams.set('scope', 'status,email');
22
22
  }
23
23
  getUrl() {
24
24
  return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
@@ -0,0 +1,6 @@
1
+ import { IOAuthPopUpDto } from './OAuthBase';
2
+ export declare class OAuthParser {
3
+ names: Array<string>;
4
+ errors: Array<string>;
5
+ parse(params: any, fragment: string): Promise<IOAuthPopUpDto>;
6
+ }
@@ -0,0 +1,37 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as _ from 'lodash';
11
+ export class OAuthParser {
12
+ constructor() {
13
+ this.names = ['code', 'access_token'];
14
+ this.errors = ['error_description', 'error'];
15
+ }
16
+ parse(params, fragment) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ let item = new URLSearchParams();
19
+ _.forIn(params, (value, key) => item.append(key, value));
20
+ new URLSearchParams(fragment).forEach((value, key) => item.append(key, value));
21
+ let oAuthError = null;
22
+ let oAuthCodeOrToken = null;
23
+ item.forEach((value, key) => {
24
+ if (this.names.includes(key)) {
25
+ oAuthCodeOrToken = value;
26
+ }
27
+ else if (this.errors.includes(key)) {
28
+ oAuthError = value;
29
+ }
30
+ if (!_.isEmpty(oAuthCodeOrToken) || !_.isEmpty(oAuthError)) {
31
+ return { oAuthCodeOrToken, oAuthError };
32
+ }
33
+ });
34
+ return null;
35
+ });
36
+ }
37
+ }
@@ -1,5 +1,6 @@
1
1
  export * from './OAuthBase';
2
2
  export * from './OAuthUser';
3
+ export * from './OAuthParser';
3
4
  export * from './go/GoUser';
4
5
  export * from './go/GoAuth';
5
6
  export * from './vk/VkUser';
package/esm/public-api.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './OAuthBase';
2
2
  export * from './OAuthUser';
3
+ export * from './OAuthParser';
3
4
  export * from './go/GoUser';
4
5
  export * from './go/GoAuth';
5
6
  export * from './vk/VkUser';
package/esm/vk/VkAuth.js CHANGED
@@ -15,7 +15,7 @@ export class VkAuth extends OAuthBase {
15
15
  constructor(logger, applicationId, window) {
16
16
  super(logger, applicationId, window);
17
17
  this.v = '5.131';
18
- this.urlParams.set('scope', 'status');
18
+ this.urlParams.set('scope', 'status,email');
19
19
  }
20
20
  getUrl() {
21
21
  return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",