@christianriedl/rest 1.0.16 → 1.0.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.
- package/dist/authorize.d.ts +13 -1
- package/dist/authorize.js +28 -8
- package/dist/authorize.js.map +1 -1
- package/package.json +1 -1
package/dist/authorize.d.ts
CHANGED
|
@@ -7,19 +7,31 @@ export interface IAuthorizeResult {
|
|
|
7
7
|
user: string;
|
|
8
8
|
password: string;
|
|
9
9
|
}
|
|
10
|
+
interface IMeta {
|
|
11
|
+
scopes: string[];
|
|
12
|
+
}
|
|
13
|
+
interface IRoute {
|
|
14
|
+
path: string;
|
|
15
|
+
meta?: IMeta;
|
|
16
|
+
}
|
|
10
17
|
export declare class Authorize {
|
|
11
18
|
rest: Rest;
|
|
12
19
|
storage: ILocalStorage;
|
|
13
20
|
secretSmarthome: string;
|
|
14
21
|
secretMedia: string;
|
|
15
22
|
scopes: Dictionary<boolean>;
|
|
23
|
+
routes: Dictionary<IRoute>;
|
|
16
24
|
password: string;
|
|
17
25
|
config: IAppConfig;
|
|
18
26
|
get user(): string;
|
|
19
27
|
set user(value: string);
|
|
20
28
|
constructor(url: string, storage: ILocalStorage, config: IAppConfig, logger: ILogger);
|
|
21
|
-
|
|
29
|
+
setScopes(scopes: string): void;
|
|
30
|
+
setRoutes(routes: IRoute[]): void;
|
|
31
|
+
checkScope(scopes: string[]): boolean;
|
|
32
|
+
checkRoute(path: string): boolean;
|
|
22
33
|
authorize(user: string, password: string): Promise<IAuthorizeResult>;
|
|
23
34
|
login(user: string, password: string): Promise<IAuthorizeResult>;
|
|
24
35
|
processResult(res: IAuthorizeResult, all: boolean): void;
|
|
25
36
|
}
|
|
37
|
+
export {};
|
package/dist/authorize.js
CHANGED
|
@@ -6,6 +6,7 @@ export class Authorize {
|
|
|
6
6
|
secretSmarthome;
|
|
7
7
|
secretMedia;
|
|
8
8
|
scopes = {};
|
|
9
|
+
routes = {};
|
|
9
10
|
password;
|
|
10
11
|
config;
|
|
11
12
|
get user() {
|
|
@@ -21,14 +22,33 @@ export class Authorize {
|
|
|
21
22
|
this.secretMedia = storage.getItemString('secretMedia', '');
|
|
22
23
|
this.secretSmarthome = storage.getItemString('secretSmarthome', '');
|
|
23
24
|
this.password = storage.getItemString('password', '');
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
this.
|
|
25
|
+
const scopes = storage.getItemString('scopes');
|
|
26
|
+
if (scopes)
|
|
27
|
+
this.setScopes(scopes);
|
|
28
|
+
}
|
|
29
|
+
setScopes(scopes) {
|
|
30
|
+
const splitScopes = scopes.split('|');
|
|
31
|
+
for (let i = 0; i < splitScopes.length; i++)
|
|
32
|
+
this.scopes[splitScopes[i]] = true;
|
|
27
33
|
}
|
|
28
34
|
setRoutes(routes) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
for (let i = 0; i < routes.length; i++) {
|
|
36
|
+
this.routes[routes[i].path] = routes[i];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
checkScope(scopes) {
|
|
40
|
+
for (let i = 0; i < scopes.length; i++)
|
|
41
|
+
if (!this.scopes[scopes[i]])
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
checkRoute(path) {
|
|
46
|
+
const route = this.routes[path];
|
|
47
|
+
if (!route)
|
|
48
|
+
return false;
|
|
49
|
+
if (route.meta)
|
|
50
|
+
return this.checkScope(route.meta.scopes);
|
|
51
|
+
return true;
|
|
32
52
|
}
|
|
33
53
|
async authorize(user, password) {
|
|
34
54
|
const result = await this.rest.postDataEx("apiauth/authorize", { user: user, password: password });
|
|
@@ -49,8 +69,8 @@ export class Authorize {
|
|
|
49
69
|
return null;
|
|
50
70
|
}
|
|
51
71
|
processResult(res, all) {
|
|
52
|
-
this.storage.setItem('
|
|
53
|
-
this.
|
|
72
|
+
this.storage.setItem('scopes', res.scopes);
|
|
73
|
+
this.setScopes(res.scopes);
|
|
54
74
|
if (all) {
|
|
55
75
|
this.password = res.password;
|
|
56
76
|
this.secretMedia = res.mediaSecret;
|
package/dist/authorize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBrC,MAAM,OAAO,SAAS;IAClB,IAAI,CAAO;IACX,OAAO,CAAgB;IACvB,eAAe,CAAS;IACxB,WAAW,CAAS;IACpB,MAAM,GAAwB,EAAE,CAAC;IACjC,MAAM,GAAuB,EAAE,CAAC;IAChC,QAAQ,CAAS;IACjB,MAAM,CAAa;IACnB,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC5B,CAAC;IACD,IAAI,IAAI,CAAC,KAAa;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;IAC7B,CAAC;IACD,YAAY,GAAW,EAAE,OAAsB,EAAE,MAAkB,EAAE,MAAe;QAChF,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;QACnE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,iBAAiB,EA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