@christianriedl/rest 1.0.53 → 1.0.54
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 +57 -55
- package/dist/authorize.js +137 -131
- package/dist/authorize.js.map +1 -1
- package/dist/dummyOauth.d.ts +10 -10
- package/dist/dummyOauth.js +23 -23
- package/dist/iOauth.d.ts +7 -7
- package/dist/iOauth.js +2 -2
- package/dist/iRest.d.ts +35 -35
- package/dist/iRest.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/oauth.d.ts +40 -40
- package/dist/oauth.js +212 -212
- package/dist/oauth.js.map +1 -1
- package/dist/rest.d.ts +32 -32
- package/dist/rest.js +323 -323
- package/dist/rest.js.map +1 -1
- package/package.json +4 -4
package/dist/oauth.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { IOAuth } from './iOauth';
|
|
2
|
-
export * from './iOauth';
|
|
3
|
-
import { ILocalStorage, ILogger } from '@christianriedl/utils';
|
|
4
|
-
import { IRestResult } from './iRest';
|
|
5
|
-
export interface IUser {
|
|
6
|
-
name: string;
|
|
7
|
-
password: string;
|
|
8
|
-
role: string;
|
|
9
|
-
}
|
|
10
|
-
export interface IRefreshTokenEntry {
|
|
11
|
-
user: string;
|
|
12
|
-
host: string;
|
|
13
|
-
token: string;
|
|
14
|
-
role: string;
|
|
15
|
-
tokenExpiresMinutes: number;
|
|
16
|
-
expireTime: Date;
|
|
17
|
-
}
|
|
18
|
-
export declare class OAuth implements IOAuth {
|
|
19
|
-
accessTokenUrl: string;
|
|
20
|
-
clientId: string;
|
|
21
|
-
role: string;
|
|
22
|
-
scope?: string;
|
|
23
|
-
clientSecret?: string;
|
|
24
|
-
openId: boolean;
|
|
25
|
-
accessToken: string;
|
|
26
|
-
refreshToken: string;
|
|
27
|
-
mode: RequestMode;
|
|
28
|
-
expiresAt: number;
|
|
29
|
-
localStorage: ILocalStorage;
|
|
30
|
-
log: ILogger;
|
|
31
|
-
constructor(accessTokenUrl: string, mode: RequestMode, localStorage: ILocalStorage, log: ILogger, scope?: string, clientId?: string, clientSecret?: string);
|
|
32
|
-
get isExpired(): boolean;
|
|
33
|
-
getToken(): Promise<string>;
|
|
34
|
-
getAccessToken(clientId: string, clientSecret: string): Promise<boolean>;
|
|
35
|
-
getUser(): Promise<IRestResult<IUser[]>>;
|
|
36
|
-
getRefreshTokenEntries(): Promise<IRestResult<IRefreshTokenEntry[]>>;
|
|
37
|
-
private storeResponse;
|
|
38
|
-
private storeError;
|
|
39
|
-
private btoa;
|
|
40
|
-
}
|
|
1
|
+
import { IOAuth } from './iOauth';
|
|
2
|
+
export * from './iOauth';
|
|
3
|
+
import { ILocalStorage, ILogger } from '@christianriedl/utils';
|
|
4
|
+
import { IRestResult } from './iRest';
|
|
5
|
+
export interface IUser {
|
|
6
|
+
name: string;
|
|
7
|
+
password: string;
|
|
8
|
+
role: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IRefreshTokenEntry {
|
|
11
|
+
user: string;
|
|
12
|
+
host: string;
|
|
13
|
+
token: string;
|
|
14
|
+
role: string;
|
|
15
|
+
tokenExpiresMinutes: number;
|
|
16
|
+
expireTime: Date;
|
|
17
|
+
}
|
|
18
|
+
export declare class OAuth implements IOAuth {
|
|
19
|
+
accessTokenUrl: string;
|
|
20
|
+
clientId: string;
|
|
21
|
+
role: string;
|
|
22
|
+
scope?: string;
|
|
23
|
+
clientSecret?: string;
|
|
24
|
+
openId: boolean;
|
|
25
|
+
accessToken: string;
|
|
26
|
+
refreshToken: string;
|
|
27
|
+
mode: RequestMode;
|
|
28
|
+
expiresAt: number;
|
|
29
|
+
localStorage: ILocalStorage;
|
|
30
|
+
log: ILogger;
|
|
31
|
+
constructor(accessTokenUrl: string, mode: RequestMode, localStorage: ILocalStorage, log: ILogger, scope?: string, clientId?: string, clientSecret?: string);
|
|
32
|
+
get isExpired(): boolean;
|
|
33
|
+
getToken(): Promise<string>;
|
|
34
|
+
getAccessToken(clientId: string, clientSecret: string): Promise<boolean>;
|
|
35
|
+
getUser(): Promise<IRestResult<IUser[]>>;
|
|
36
|
+
getRefreshTokenEntries(): Promise<IRestResult<IRefreshTokenEntry[]>>;
|
|
37
|
+
private storeResponse;
|
|
38
|
+
private storeError;
|
|
39
|
+
private btoa;
|
|
40
|
+
}
|
package/dist/oauth.js
CHANGED
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
export * from './iOauth';
|
|
2
|
-
import { Rest } from './rest';
|
|
3
|
-
;
|
|
4
|
-
;
|
|
5
|
-
;
|
|
6
|
-
export class OAuth {
|
|
7
|
-
accessTokenUrl;
|
|
8
|
-
clientId;
|
|
9
|
-
role;
|
|
10
|
-
scope;
|
|
11
|
-
clientSecret;
|
|
12
|
-
openId;
|
|
13
|
-
accessToken;
|
|
14
|
-
refreshToken;
|
|
15
|
-
mode;
|
|
16
|
-
expiresAt;
|
|
17
|
-
localStorage;
|
|
18
|
-
log;
|
|
19
|
-
// ACM
|
|
20
|
-
constructor(accessTokenUrl, mode, localStorage, log, scope, clientId, clientSecret) {
|
|
21
|
-
this.accessTokenUrl = accessTokenUrl;
|
|
22
|
-
this.mode = mode;
|
|
23
|
-
this.scope = scope;
|
|
24
|
-
this.openId = !!clientId && !!clientSecret;
|
|
25
|
-
this.localStorage = localStorage;
|
|
26
|
-
this.log = log;
|
|
27
|
-
this.accessToken = "";
|
|
28
|
-
this.refreshToken = "";
|
|
29
|
-
this.expiresAt = new Date().getTime();
|
|
30
|
-
if (clientId) {
|
|
31
|
-
this.clientId = clientId;
|
|
32
|
-
this.clientSecret = clientSecret;
|
|
33
|
-
this.role = "";
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.clientId = this.localStorage.getItemString('clientId', '');
|
|
37
|
-
this.role = this.localStorage.getItemString('role', '');
|
|
38
|
-
}
|
|
39
|
-
this.accessToken = this.localStorage.getItemString('accessToken', '');
|
|
40
|
-
this.refreshToken = this.localStorage.getItemString('refreshToken', '');
|
|
41
|
-
this.log.trace(`stored accessToken ${this.clientId} : ${this.accessToken}`);
|
|
42
|
-
const expiresAt = this.localStorage.getItemNumber('expiresAt');
|
|
43
|
-
if (expiresAt > 0) {
|
|
44
|
-
this.expiresAt = expiresAt;
|
|
45
|
-
this.log.trace(`Stored ${this.clientId} expiresAt : ${new Date(expiresAt)}`);
|
|
46
|
-
if (this.isExpired) {
|
|
47
|
-
this.log.trace(`${this.clientId} already expired`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// OpenID
|
|
52
|
-
get isExpired() {
|
|
53
|
-
if (this.accessToken) {
|
|
54
|
-
const now = new Date();
|
|
55
|
-
return now.getTime() >= this.expiresAt;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
getToken() {
|
|
60
|
-
const self = this;
|
|
61
|
-
return new Promise(function (resolve, reject) {
|
|
62
|
-
if (!self.isExpired) {
|
|
63
|
-
resolve(self.accessToken);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
let body;
|
|
67
|
-
let url;
|
|
68
|
-
let authorization;
|
|
69
|
-
const header = {};
|
|
70
|
-
if (self.openId) {
|
|
71
|
-
url = self.accessTokenUrl;
|
|
72
|
-
authorization = 'Basic ' + /*window.*/ btoa(`${self.clientId}:${self.clientSecret}`);
|
|
73
|
-
body = 'grant_type=client_credentials&scope=' + self.scope;
|
|
74
|
-
header['Origin'] = 'https://www.christian-riedl.com';
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
url = self.accessTokenUrl + "/refresh?refreshToken=" + self.refreshToken;
|
|
78
|
-
body = undefined;
|
|
79
|
-
authorization = Rest.bearerAuth(self.refreshToken);
|
|
80
|
-
}
|
|
81
|
-
Rest.fetch(url, "POST", self.mode, body, authorization, (result) => {
|
|
82
|
-
if (result && result.ok) {
|
|
83
|
-
self.storeResponse(result.result, false);
|
|
84
|
-
self.log.trace(`Got refreshed access token ${self.clientId}, expires at ${new Date(self.expiresAt)}`);
|
|
85
|
-
resolve(self.accessToken);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
self.storeError();
|
|
89
|
-
const statusCode = result ? result.statusCode : -1;
|
|
90
|
-
self.log.warning(`Get token ${self.clientId}: ${result || statusCode}`);
|
|
91
|
-
reject({ reason: statusCode });
|
|
92
|
-
}
|
|
93
|
-
}, (reason) => {
|
|
94
|
-
self.storeError();
|
|
95
|
-
self.log.warning(`Get token ${self.clientId}: ${reason}`);
|
|
96
|
-
reject(reason);
|
|
97
|
-
}, self.log, undefined, 'application/x-www-form-urlencoded; charset=utf-8', header);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
getAccessToken(clientId, clientSecret) {
|
|
101
|
-
const self = this;
|
|
102
|
-
this.clientId = clientId;
|
|
103
|
-
this.localStorage.setItem('clientId', this.clientId);
|
|
104
|
-
return new Promise(function (resolve, reject) {
|
|
105
|
-
const authorization = 'Basic ' + /* window.*/ btoa(`${clientId}:${clientSecret}`);
|
|
106
|
-
const url = self.accessTokenUrl;
|
|
107
|
-
Rest.fetch(url, "POST", self.mode, undefined, authorization, (result) => {
|
|
108
|
-
if (result && result.ok) {
|
|
109
|
-
self.storeResponse(result.result, true);
|
|
110
|
-
self.log.trace(`Got access token ${self.clientId}, expires at ${new Date(self.expiresAt)}`);
|
|
111
|
-
resolve(true);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
self.storeError();
|
|
115
|
-
const statusCode = result ? result.statusCode : -1;
|
|
116
|
-
self.log.warning(`Get access token ${self.clientId}: ${statusCode}`);
|
|
117
|
-
reject({ reason: statusCode });
|
|
118
|
-
}
|
|
119
|
-
}, (reason) => {
|
|
120
|
-
self.storeError();
|
|
121
|
-
self.log.warning(`Get access token ${self.clientId}: ${reason}`);
|
|
122
|
-
reject(reason);
|
|
123
|
-
}, self.log);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
getUser() {
|
|
127
|
-
const self = this;
|
|
128
|
-
return new Promise(function (resolve, reject) {
|
|
129
|
-
const url = self.accessTokenUrl + "authenticate/user";
|
|
130
|
-
return Rest.fetch(url, 'GET', self.mode, undefined, Rest.bearerAuth(self.accessToken), resolve, reject, self.log);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
getRefreshTokenEntries() {
|
|
134
|
-
const self = this;
|
|
135
|
-
return new Promise(function (resolve, reject) {
|
|
136
|
-
const url = self.accessTokenUrl + "authenticate/token/refresh";
|
|
137
|
-
return Rest.fetch(url, 'GET', self.mode, undefined, Rest.bearerAuth(self.accessToken), resolve, reject, self.log, (result) => {
|
|
138
|
-
if (result.result) {
|
|
139
|
-
const data = result.result;
|
|
140
|
-
for (let i = 0; i < data.length; i++) {
|
|
141
|
-
data[i].expireTime = new Date(data[i].expireTime);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
storeResponse(data, withRefreshToken) {
|
|
148
|
-
this.accessToken = data.access_token;
|
|
149
|
-
if (data.role) {
|
|
150
|
-
this.role = data.role;
|
|
151
|
-
this.localStorage.setItem('role', this.role);
|
|
152
|
-
}
|
|
153
|
-
this.expiresAt = new Date().getTime() + data.expires_in * 1000;
|
|
154
|
-
this.localStorage.setItem('expiresAt', this.expiresAt.toString());
|
|
155
|
-
this.localStorage.setItem('accessToken', this.accessToken);
|
|
156
|
-
if (withRefreshToken) {
|
|
157
|
-
this.refreshToken = data.refresh_token;
|
|
158
|
-
this.localStorage.setItem('refreshToken', this.refreshToken);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
storeError() {
|
|
162
|
-
this.expiresAt = new Date().getTime();
|
|
163
|
-
this.localStorage.setItem('expiresAt', this.expiresAt.toString());
|
|
164
|
-
}
|
|
165
|
-
btoa(input) {
|
|
166
|
-
const TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
167
|
-
if (/[^\0-\xFF]/.test(input)) {
|
|
168
|
-
// Note: no need to special-case astral symbols here, as surrogates are
|
|
169
|
-
// matched, and the input is supposed to only contain ASCII anyway.
|
|
170
|
-
throw Error('The string to be encoded contains characters outside of the ' +
|
|
171
|
-
'Latin1 range.');
|
|
172
|
-
}
|
|
173
|
-
let padding = input.length % 3;
|
|
174
|
-
let output = '';
|
|
175
|
-
let position = -1;
|
|
176
|
-
let a;
|
|
177
|
-
let b;
|
|
178
|
-
let c;
|
|
179
|
-
let buffer;
|
|
180
|
-
// Make sure any padding is handled outside of the loop.
|
|
181
|
-
let length = input.length - padding;
|
|
182
|
-
while (++position < length) {
|
|
183
|
-
// Read three bytes, i.e. 24 bits.
|
|
184
|
-
a = input.charCodeAt(position) << 16;
|
|
185
|
-
b = input.charCodeAt(++position) << 8;
|
|
186
|
-
c = input.charCodeAt(++position);
|
|
187
|
-
buffer = a + b + c;
|
|
188
|
-
// Turn the 24 bits into four chunks of 6 bits each, and append the
|
|
189
|
-
// matching character for each of them to the output.
|
|
190
|
-
output += (TABLE.charAt(buffer >> 18 & 0x3F) +
|
|
191
|
-
TABLE.charAt(buffer >> 12 & 0x3F) +
|
|
192
|
-
TABLE.charAt(buffer >> 6 & 0x3F) +
|
|
193
|
-
TABLE.charAt(buffer & 0x3F));
|
|
194
|
-
}
|
|
195
|
-
if (padding == 2) {
|
|
196
|
-
a = input.charCodeAt(position) << 8;
|
|
197
|
-
b = input.charCodeAt(++position);
|
|
198
|
-
buffer = a + b;
|
|
199
|
-
output += (TABLE.charAt(buffer >> 10) +
|
|
200
|
-
TABLE.charAt((buffer >> 4) & 0x3F) +
|
|
201
|
-
TABLE.charAt((buffer << 2) & 0x3F) +
|
|
202
|
-
'=');
|
|
203
|
-
}
|
|
204
|
-
else if (padding == 1) {
|
|
205
|
-
buffer = input.charCodeAt(position);
|
|
206
|
-
output += (TABLE.charAt(buffer >> 2) +
|
|
207
|
-
TABLE.charAt((buffer << 4) & 0x3F) +
|
|
208
|
-
'==');
|
|
209
|
-
}
|
|
210
|
-
return output;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
1
|
+
export * from './iOauth';
|
|
2
|
+
import { Rest } from './rest';
|
|
3
|
+
;
|
|
4
|
+
;
|
|
5
|
+
;
|
|
6
|
+
export class OAuth {
|
|
7
|
+
accessTokenUrl;
|
|
8
|
+
clientId;
|
|
9
|
+
role;
|
|
10
|
+
scope;
|
|
11
|
+
clientSecret;
|
|
12
|
+
openId;
|
|
13
|
+
accessToken;
|
|
14
|
+
refreshToken;
|
|
15
|
+
mode;
|
|
16
|
+
expiresAt;
|
|
17
|
+
localStorage;
|
|
18
|
+
log;
|
|
19
|
+
// ACM
|
|
20
|
+
constructor(accessTokenUrl, mode, localStorage, log, scope, clientId, clientSecret) {
|
|
21
|
+
this.accessTokenUrl = accessTokenUrl;
|
|
22
|
+
this.mode = mode;
|
|
23
|
+
this.scope = scope;
|
|
24
|
+
this.openId = !!clientId && !!clientSecret;
|
|
25
|
+
this.localStorage = localStorage;
|
|
26
|
+
this.log = log;
|
|
27
|
+
this.accessToken = "";
|
|
28
|
+
this.refreshToken = "";
|
|
29
|
+
this.expiresAt = new Date().getTime();
|
|
30
|
+
if (clientId) {
|
|
31
|
+
this.clientId = clientId;
|
|
32
|
+
this.clientSecret = clientSecret;
|
|
33
|
+
this.role = "";
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.clientId = this.localStorage.getItemString('clientId', '');
|
|
37
|
+
this.role = this.localStorage.getItemString('role', '');
|
|
38
|
+
}
|
|
39
|
+
this.accessToken = this.localStorage.getItemString('accessToken', '');
|
|
40
|
+
this.refreshToken = this.localStorage.getItemString('refreshToken', '');
|
|
41
|
+
this.log.trace(`stored accessToken ${this.clientId} : ${this.accessToken}`);
|
|
42
|
+
const expiresAt = this.localStorage.getItemNumber('expiresAt');
|
|
43
|
+
if (expiresAt > 0) {
|
|
44
|
+
this.expiresAt = expiresAt;
|
|
45
|
+
this.log.trace(`Stored ${this.clientId} expiresAt : ${new Date(expiresAt)}`);
|
|
46
|
+
if (this.isExpired) {
|
|
47
|
+
this.log.trace(`${this.clientId} already expired`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// OpenID
|
|
52
|
+
get isExpired() {
|
|
53
|
+
if (this.accessToken) {
|
|
54
|
+
const now = new Date();
|
|
55
|
+
return now.getTime() >= this.expiresAt;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
getToken() {
|
|
60
|
+
const self = this;
|
|
61
|
+
return new Promise(function (resolve, reject) {
|
|
62
|
+
if (!self.isExpired) {
|
|
63
|
+
resolve(self.accessToken);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let body;
|
|
67
|
+
let url;
|
|
68
|
+
let authorization;
|
|
69
|
+
const header = {};
|
|
70
|
+
if (self.openId) {
|
|
71
|
+
url = self.accessTokenUrl;
|
|
72
|
+
authorization = 'Basic ' + /*window.*/ btoa(`${self.clientId}:${self.clientSecret}`);
|
|
73
|
+
body = 'grant_type=client_credentials&scope=' + self.scope;
|
|
74
|
+
header['Origin'] = 'https://www.christian-riedl.com';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
url = self.accessTokenUrl + "/refresh?refreshToken=" + self.refreshToken;
|
|
78
|
+
body = undefined;
|
|
79
|
+
authorization = Rest.bearerAuth(self.refreshToken);
|
|
80
|
+
}
|
|
81
|
+
Rest.fetch(url, "POST", self.mode, body, authorization, (result) => {
|
|
82
|
+
if (result && result.ok) {
|
|
83
|
+
self.storeResponse(result.result, false);
|
|
84
|
+
self.log.trace(`Got refreshed access token ${self.clientId}, expires at ${new Date(self.expiresAt)}`);
|
|
85
|
+
resolve(self.accessToken);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
self.storeError();
|
|
89
|
+
const statusCode = result ? result.statusCode : -1;
|
|
90
|
+
self.log.warning(`Get token ${self.clientId}: ${result || statusCode}`);
|
|
91
|
+
reject({ reason: statusCode });
|
|
92
|
+
}
|
|
93
|
+
}, (reason) => {
|
|
94
|
+
self.storeError();
|
|
95
|
+
self.log.warning(`Get token ${self.clientId}: ${reason}`);
|
|
96
|
+
reject(reason);
|
|
97
|
+
}, self.log, undefined, 'application/x-www-form-urlencoded; charset=utf-8', header);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getAccessToken(clientId, clientSecret) {
|
|
101
|
+
const self = this;
|
|
102
|
+
this.clientId = clientId;
|
|
103
|
+
this.localStorage.setItem('clientId', this.clientId);
|
|
104
|
+
return new Promise(function (resolve, reject) {
|
|
105
|
+
const authorization = 'Basic ' + /* window.*/ btoa(`${clientId}:${clientSecret}`);
|
|
106
|
+
const url = self.accessTokenUrl;
|
|
107
|
+
Rest.fetch(url, "POST", self.mode, undefined, authorization, (result) => {
|
|
108
|
+
if (result && result.ok) {
|
|
109
|
+
self.storeResponse(result.result, true);
|
|
110
|
+
self.log.trace(`Got access token ${self.clientId}, expires at ${new Date(self.expiresAt)}`);
|
|
111
|
+
resolve(true);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
self.storeError();
|
|
115
|
+
const statusCode = result ? result.statusCode : -1;
|
|
116
|
+
self.log.warning(`Get access token ${self.clientId}: ${statusCode}`);
|
|
117
|
+
reject({ reason: statusCode });
|
|
118
|
+
}
|
|
119
|
+
}, (reason) => {
|
|
120
|
+
self.storeError();
|
|
121
|
+
self.log.warning(`Get access token ${self.clientId}: ${reason}`);
|
|
122
|
+
reject(reason);
|
|
123
|
+
}, self.log);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
getUser() {
|
|
127
|
+
const self = this;
|
|
128
|
+
return new Promise(function (resolve, reject) {
|
|
129
|
+
const url = self.accessTokenUrl + "authenticate/user";
|
|
130
|
+
return Rest.fetch(url, 'GET', self.mode, undefined, Rest.bearerAuth(self.accessToken), resolve, reject, self.log);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
getRefreshTokenEntries() {
|
|
134
|
+
const self = this;
|
|
135
|
+
return new Promise(function (resolve, reject) {
|
|
136
|
+
const url = self.accessTokenUrl + "authenticate/token/refresh";
|
|
137
|
+
return Rest.fetch(url, 'GET', self.mode, undefined, Rest.bearerAuth(self.accessToken), resolve, reject, self.log, (result) => {
|
|
138
|
+
if (result.result) {
|
|
139
|
+
const data = result.result;
|
|
140
|
+
for (let i = 0; i < data.length; i++) {
|
|
141
|
+
data[i].expireTime = new Date(data[i].expireTime);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
storeResponse(data, withRefreshToken) {
|
|
148
|
+
this.accessToken = data.access_token;
|
|
149
|
+
if (data.role) {
|
|
150
|
+
this.role = data.role;
|
|
151
|
+
this.localStorage.setItem('role', this.role);
|
|
152
|
+
}
|
|
153
|
+
this.expiresAt = new Date().getTime() + data.expires_in * 1000;
|
|
154
|
+
this.localStorage.setItem('expiresAt', this.expiresAt.toString());
|
|
155
|
+
this.localStorage.setItem('accessToken', this.accessToken);
|
|
156
|
+
if (withRefreshToken) {
|
|
157
|
+
this.refreshToken = data.refresh_token;
|
|
158
|
+
this.localStorage.setItem('refreshToken', this.refreshToken);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
storeError() {
|
|
162
|
+
this.expiresAt = new Date().getTime();
|
|
163
|
+
this.localStorage.setItem('expiresAt', this.expiresAt.toString());
|
|
164
|
+
}
|
|
165
|
+
btoa(input) {
|
|
166
|
+
const TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
167
|
+
if (/[^\0-\xFF]/.test(input)) {
|
|
168
|
+
// Note: no need to special-case astral symbols here, as surrogates are
|
|
169
|
+
// matched, and the input is supposed to only contain ASCII anyway.
|
|
170
|
+
throw Error('The string to be encoded contains characters outside of the ' +
|
|
171
|
+
'Latin1 range.');
|
|
172
|
+
}
|
|
173
|
+
let padding = input.length % 3;
|
|
174
|
+
let output = '';
|
|
175
|
+
let position = -1;
|
|
176
|
+
let a;
|
|
177
|
+
let b;
|
|
178
|
+
let c;
|
|
179
|
+
let buffer;
|
|
180
|
+
// Make sure any padding is handled outside of the loop.
|
|
181
|
+
let length = input.length - padding;
|
|
182
|
+
while (++position < length) {
|
|
183
|
+
// Read three bytes, i.e. 24 bits.
|
|
184
|
+
a = input.charCodeAt(position) << 16;
|
|
185
|
+
b = input.charCodeAt(++position) << 8;
|
|
186
|
+
c = input.charCodeAt(++position);
|
|
187
|
+
buffer = a + b + c;
|
|
188
|
+
// Turn the 24 bits into four chunks of 6 bits each, and append the
|
|
189
|
+
// matching character for each of them to the output.
|
|
190
|
+
output += (TABLE.charAt(buffer >> 18 & 0x3F) +
|
|
191
|
+
TABLE.charAt(buffer >> 12 & 0x3F) +
|
|
192
|
+
TABLE.charAt(buffer >> 6 & 0x3F) +
|
|
193
|
+
TABLE.charAt(buffer & 0x3F));
|
|
194
|
+
}
|
|
195
|
+
if (padding == 2) {
|
|
196
|
+
a = input.charCodeAt(position) << 8;
|
|
197
|
+
b = input.charCodeAt(++position);
|
|
198
|
+
buffer = a + b;
|
|
199
|
+
output += (TABLE.charAt(buffer >> 10) +
|
|
200
|
+
TABLE.charAt((buffer >> 4) & 0x3F) +
|
|
201
|
+
TABLE.charAt((buffer << 2) & 0x3F) +
|
|
202
|
+
'=');
|
|
203
|
+
}
|
|
204
|
+
else if (padding == 1) {
|
|
205
|
+
buffer = input.charCodeAt(position);
|
|
206
|
+
output += (TABLE.charAt(buffer >> 2) +
|
|
207
|
+
TABLE.charAt((buffer << 4) & 0x3F) +
|
|
208
|
+
'==');
|
|
209
|
+
}
|
|
210
|
+
return output;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
213
|
//# sourceMappingURL=oauth.js.map
|
package/dist/oauth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAO5B,CAAC;AAQD,CAAC;AASD,CAAC;AAEF,MAAM,OAAO,KAAK;IACd,cAAc,CAAS;IACvB,QAAQ,CAAS;IACjB,IAAI,CAAS;IACb,KAAK,CAAU;IACf,YAAY,CAAU;IACtB,MAAM,CAAU;IAChB,WAAW,CAAS;IACpB,YAAY,CAAS;IACrB,IAAI,CAAc;IAClB,SAAS,CAAS;IAClB,YAAY,CAAgB;IAC5B,GAAG,CAAU;IAEb,OAAO;IACP,YAAY,cAAsB,EAAE,IAAiB,EAAE,YAA2B,EAAE,GAAY,EACpF,KAAc,EAAE,QAAiB,EAAE,YAAqB;QAChE,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,YAAY,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACtC,IAAI,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAO5B,CAAC;AAQD,CAAC;AASD,CAAC;AAEF,MAAM,OAAO,KAAK;IACd,cAAc,CAAS;IACvB,QAAQ,CAAS;IACj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';
|
|
2
|
-
export * from './iRest';
|
|
3
|
-
import { IOAuth } from './iOauth';
|
|
4
|
-
import { ILogger } from '@christianriedl/utils';
|
|
5
|
-
|
|
6
|
-
[key: string]: T;
|
|
7
|
-
};
|
|
8
|
-
export declare class Rest implements IRest {
|
|
9
|
-
log?: ILogger;
|
|
10
|
-
logErr?: ILogger;
|
|
11
|
-
auth: IOAuth;
|
|
12
|
-
mode: RequestMode;
|
|
13
|
-
serviceUrl: string;
|
|
14
|
-
constructor(serviceUrl: string, mode: RequestMode, oauth: IOAuth, log?: ILogger, logErr?: boolean);
|
|
15
|
-
static buildUrl(url: string, parameters?: Dictionary<any>): string;
|
|
16
|
-
static fetch<T>(url: string, method: string, requestMode: RequestMode, body: any | undefined, authorization: string | undefined, resolve: (value?: IRestResult<T>) => void, reject: (reason?: any) => void, log?: ILogger, adjustResult?: (result: IRestResult<T>) => void, contentType?: string, headers?: Dictionary<string>): void;
|
|
17
|
-
static fetchBlob<RESP>(url: string, requestMode: RequestMode, blob: Blob, mediaType: string, responseType: string | undefined, authorization: string | undefined, resolve: (value?: IRestResult<RESP>) => void, reject: (reason?: any) => void, log?: ILogger): void;
|
|
18
|
-
static getBlob(url: string, requestMode: RequestMode, mediaType: string | undefined, authorization: string | undefined, resolve: (value?: IRestResult<Blob>) => void, reject: (reason?: any) => void, headers?: Dictionary<string>, log?: ILogger): void;
|
|
19
|
-
static bearerAuth(token: string): string | undefined;
|
|
20
|
-
toBoolean(result: Promise<IRestResult<boolean>>): Promise<boolean>;
|
|
21
|
-
toData<T>(result: Promise<IRestResult<T>>): Promise<T>;
|
|
22
|
-
toPromise<T>(data: T): Promise<T>;
|
|
23
|
-
getData<T>(path: string, queryParameter?: Dictionary<any>, adjustResult?: (result: IRestResult<T>) => void): Promise<IRestResult<T>>;
|
|
24
|
-
postData<T>(path: string, data?: T): Promise<IRestResult<boolean>>;
|
|
25
|
-
putData<T, R>(path: string, data?: T, adjustResult?: (result: IRestResult<R>) => void): Promise<IRestResult<R>>;
|
|
26
|
-
postDataEx<PAYLOAD, REPLY>(path: string, data?: PAYLOAD, adjustResult?: (result: IRestResult<REPLY>) => void): Promise<IRestResult<REPLY>>;
|
|
27
|
-
postBlob<RESP>(path: string, blob: Blob, mediaType?: string, responseType?: string): Promise<IRestResult<RESP>>;
|
|
28
|
-
getBlob(path: string, mediaType: string, queryParameter?: Dictionary<any>, headers?: Dictionary<string>): Promise<IRestResult<Blob>>;
|
|
29
|
-
deleteData<T, R>(path: string, data?: T, adjustResult?: (result: IRestResult<R>) => void): Promise<IRestResult<R>>;
|
|
30
|
-
static combinedResponse<R>(response: Response, contentType?: string, log?: ILogger): Promise<IRestResult<R>>;
|
|
31
|
-
trace(msg: string, url: string, data?: any): void;
|
|
32
|
-
}
|
|
1
|
+
import { IRestResult, IRest } from './iRest';
|
|
2
|
+
export * from './iRest';
|
|
3
|
+
import { IOAuth } from './iOauth';
|
|
4
|
+
import { ILogger } from '@christianriedl/utils';
|
|
5
|
+
type Dictionary<T> = {
|
|
6
|
+
[key: string]: T;
|
|
7
|
+
};
|
|
8
|
+
export declare class Rest implements IRest {
|
|
9
|
+
log?: ILogger;
|
|
10
|
+
logErr?: ILogger;
|
|
11
|
+
auth: IOAuth;
|
|
12
|
+
mode: RequestMode;
|
|
13
|
+
serviceUrl: string;
|
|
14
|
+
constructor(serviceUrl: string, mode: RequestMode, oauth: IOAuth, log?: ILogger, logErr?: boolean);
|
|
15
|
+
static buildUrl(url: string, parameters?: Dictionary<any>): string;
|
|
16
|
+
static fetch<T>(url: string, method: string, requestMode: RequestMode, body: any | undefined, authorization: string | undefined, resolve: (value?: IRestResult<T>) => void, reject: (reason?: any) => void, log?: ILogger, adjustResult?: (result: IRestResult<T>) => void, contentType?: string, headers?: Dictionary<string>): void;
|
|
17
|
+
static fetchBlob<RESP>(url: string, requestMode: RequestMode, blob: Blob, mediaType: string, responseType: string | undefined, authorization: string | undefined, resolve: (value?: IRestResult<RESP>) => void, reject: (reason?: any) => void, log?: ILogger): void;
|
|
18
|
+
static getBlob(url: string, requestMode: RequestMode, mediaType: string | undefined, authorization: string | undefined, resolve: (value?: IRestResult<Blob>) => void, reject: (reason?: any) => void, headers?: Dictionary<string>, log?: ILogger): void;
|
|
19
|
+
static bearerAuth(token: string): string | undefined;
|
|
20
|
+
toBoolean(result: Promise<IRestResult<boolean>>): Promise<boolean>;
|
|
21
|
+
toData<T>(result: Promise<IRestResult<T>>): Promise<T>;
|
|
22
|
+
toPromise<T>(data: T): Promise<T>;
|
|
23
|
+
getData<T>(path: string, queryParameter?: Dictionary<any>, adjustResult?: (result: IRestResult<T>) => void): Promise<IRestResult<T>>;
|
|
24
|
+
postData<T>(path: string, data?: T): Promise<IRestResult<boolean>>;
|
|
25
|
+
putData<T, R>(path: string, data?: T, adjustResult?: (result: IRestResult<R>) => void): Promise<IRestResult<R>>;
|
|
26
|
+
postDataEx<PAYLOAD, REPLY>(path: string, data?: PAYLOAD, adjustResult?: (result: IRestResult<REPLY>) => void): Promise<IRestResult<REPLY>>;
|
|
27
|
+
postBlob<RESP>(path: string, blob: Blob, mediaType?: string, responseType?: string): Promise<IRestResult<RESP>>;
|
|
28
|
+
getBlob(path: string, mediaType: string, queryParameter?: Dictionary<any>, headers?: Dictionary<string>): Promise<IRestResult<Blob>>;
|
|
29
|
+
deleteData<T, R>(path: string, data?: T, adjustResult?: (result: IRestResult<R>) => void): Promise<IRestResult<R>>;
|
|
30
|
+
static combinedResponse<R>(response: Response, contentType?: string, log?: ILogger): Promise<IRestResult<R>>;
|
|
31
|
+
trace(msg: string, url: string, data?: any): void;
|
|
32
|
+
}
|