@ts-core/oauth 3.1.10 → 3.1.11
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.
- package/cjs/tg/TgAuth.d.ts +4 -0
- package/cjs/tg/TgAuth.js +50 -0
- package/esm/tg/TgAuth.d.ts +4 -0
- package/esm/tg/TgAuth.js +50 -0
- package/package.json +1 -1
package/cjs/tg/TgAuth.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { ExtendedError, ILogger, LoggerWrapper, PromiseHandler } from "@ts-core/
|
|
|
2
2
|
import { TgUser } from "./TgUser";
|
|
3
3
|
import { ITgApiLoader } from "./TgApiLoader";
|
|
4
4
|
export declare class TgAuth extends LoggerWrapper {
|
|
5
|
+
static getInitData(locationHash: string): any;
|
|
6
|
+
private static urlParseHashParams;
|
|
7
|
+
private static urlParseQueryString;
|
|
8
|
+
private static urlSafeDecode;
|
|
5
9
|
protected promise: PromiseHandler<TgUser, ExtendedError>;
|
|
6
10
|
protected settings: ITgAuthSettings;
|
|
7
11
|
constructor(logger: ILogger, settings: ITgAuthSettings);
|
package/cjs/tg/TgAuth.js
CHANGED
|
@@ -15,6 +15,56 @@ const TgUser_1 = require("./TgUser");
|
|
|
15
15
|
const PopUpBase_1 = require("../PopUpBase");
|
|
16
16
|
const _ = require("lodash");
|
|
17
17
|
class TgAuth extends common_1.LoggerWrapper {
|
|
18
|
+
static getInitData(locationHash) {
|
|
19
|
+
let item = TgAuth.urlParseHashParams(locationHash);
|
|
20
|
+
return item.tgWebAppData;
|
|
21
|
+
}
|
|
22
|
+
static urlParseHashParams(locationHash) {
|
|
23
|
+
locationHash = locationHash.replace(/^#/, '');
|
|
24
|
+
let params = {};
|
|
25
|
+
if (_.isEmpty(locationHash)) {
|
|
26
|
+
return params;
|
|
27
|
+
}
|
|
28
|
+
if (locationHash.indexOf('=') < 0 && locationHash.indexOf('?') < 0) {
|
|
29
|
+
params._path = TgAuth.urlSafeDecode(locationHash);
|
|
30
|
+
return params;
|
|
31
|
+
}
|
|
32
|
+
let qIndex = locationHash.indexOf('?');
|
|
33
|
+
if (qIndex >= 0) {
|
|
34
|
+
var pathParam = locationHash.substr(0, qIndex);
|
|
35
|
+
params._path = TgAuth.urlSafeDecode(pathParam);
|
|
36
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
37
|
+
}
|
|
38
|
+
let query_params = TgAuth.urlParseQueryString(locationHash);
|
|
39
|
+
for (var k in query_params) {
|
|
40
|
+
params[k] = query_params[k];
|
|
41
|
+
}
|
|
42
|
+
return params;
|
|
43
|
+
}
|
|
44
|
+
static urlParseQueryString(queryString) {
|
|
45
|
+
var params = {};
|
|
46
|
+
if (!queryString.length) {
|
|
47
|
+
return params;
|
|
48
|
+
}
|
|
49
|
+
let queryStringParams = queryString.split('&');
|
|
50
|
+
let i, param, paramName, paramValue;
|
|
51
|
+
for (i = 0; i < queryStringParams.length; i++) {
|
|
52
|
+
param = queryStringParams[i].split(/=(.+)/);
|
|
53
|
+
paramName = TgAuth.urlSafeDecode(param[0]);
|
|
54
|
+
paramValue = param[1] == null ? null : TgAuth.urlSafeDecode(param[1]);
|
|
55
|
+
params[paramName] = paramValue;
|
|
56
|
+
}
|
|
57
|
+
return params;
|
|
58
|
+
}
|
|
59
|
+
static urlSafeDecode(item) {
|
|
60
|
+
try {
|
|
61
|
+
item = item.replace(/\+/g, '%20');
|
|
62
|
+
return decodeURIComponent(item);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return item;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
18
68
|
constructor(logger, settings) {
|
|
19
69
|
super(logger);
|
|
20
70
|
this.settings = settings;
|
package/esm/tg/TgAuth.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { ExtendedError, ILogger, LoggerWrapper, PromiseHandler } from "@ts-core/
|
|
|
2
2
|
import { TgUser } from "./TgUser";
|
|
3
3
|
import { ITgApiLoader } from "./TgApiLoader";
|
|
4
4
|
export declare class TgAuth extends LoggerWrapper {
|
|
5
|
+
static getInitData(locationHash: string): any;
|
|
6
|
+
private static urlParseHashParams;
|
|
7
|
+
private static urlParseQueryString;
|
|
8
|
+
private static urlSafeDecode;
|
|
5
9
|
protected promise: PromiseHandler<TgUser, ExtendedError>;
|
|
6
10
|
protected settings: ITgAuthSettings;
|
|
7
11
|
constructor(logger: ILogger, settings: ITgAuthSettings);
|
package/esm/tg/TgAuth.js
CHANGED
|
@@ -12,6 +12,56 @@ import { TgUser } from "./TgUser";
|
|
|
12
12
|
import { PopUpBase } from "../PopUpBase";
|
|
13
13
|
import * as _ from 'lodash';
|
|
14
14
|
export class TgAuth extends LoggerWrapper {
|
|
15
|
+
static getInitData(locationHash) {
|
|
16
|
+
let item = TgAuth.urlParseHashParams(locationHash);
|
|
17
|
+
return item.tgWebAppData;
|
|
18
|
+
}
|
|
19
|
+
static urlParseHashParams(locationHash) {
|
|
20
|
+
locationHash = locationHash.replace(/^#/, '');
|
|
21
|
+
let params = {};
|
|
22
|
+
if (_.isEmpty(locationHash)) {
|
|
23
|
+
return params;
|
|
24
|
+
}
|
|
25
|
+
if (locationHash.indexOf('=') < 0 && locationHash.indexOf('?') < 0) {
|
|
26
|
+
params._path = TgAuth.urlSafeDecode(locationHash);
|
|
27
|
+
return params;
|
|
28
|
+
}
|
|
29
|
+
let qIndex = locationHash.indexOf('?');
|
|
30
|
+
if (qIndex >= 0) {
|
|
31
|
+
var pathParam = locationHash.substr(0, qIndex);
|
|
32
|
+
params._path = TgAuth.urlSafeDecode(pathParam);
|
|
33
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
34
|
+
}
|
|
35
|
+
let query_params = TgAuth.urlParseQueryString(locationHash);
|
|
36
|
+
for (var k in query_params) {
|
|
37
|
+
params[k] = query_params[k];
|
|
38
|
+
}
|
|
39
|
+
return params;
|
|
40
|
+
}
|
|
41
|
+
static urlParseQueryString(queryString) {
|
|
42
|
+
var params = {};
|
|
43
|
+
if (!queryString.length) {
|
|
44
|
+
return params;
|
|
45
|
+
}
|
|
46
|
+
let queryStringParams = queryString.split('&');
|
|
47
|
+
let i, param, paramName, paramValue;
|
|
48
|
+
for (i = 0; i < queryStringParams.length; i++) {
|
|
49
|
+
param = queryStringParams[i].split(/=(.+)/);
|
|
50
|
+
paramName = TgAuth.urlSafeDecode(param[0]);
|
|
51
|
+
paramValue = param[1] == null ? null : TgAuth.urlSafeDecode(param[1]);
|
|
52
|
+
params[paramName] = paramValue;
|
|
53
|
+
}
|
|
54
|
+
return params;
|
|
55
|
+
}
|
|
56
|
+
static urlSafeDecode(item) {
|
|
57
|
+
try {
|
|
58
|
+
item = item.replace(/\+/g, '%20');
|
|
59
|
+
return decodeURIComponent(item);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return item;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
15
65
|
constructor(logger, settings) {
|
|
16
66
|
super(logger);
|
|
17
67
|
this.settings = settings;
|