@delon/auth 12.4.2 → 13.0.0-beta.1
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/auth.d.ts +1 -0
- package/{esm2015/auth.js → esm2020/auth.mjs} +0 -0
- package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- package/{esm2015/src/auth.config.js → esm2020/src/auth.config.mjs} +0 -0
- package/esm2020/src/auth.module.mjs +12 -0
- package/esm2020/src/social/social.service.mjs +105 -0
- package/{esm2015/src/store/cookie-storage.service.js → esm2020/src/store/cookie-storage.service.mjs} +0 -0
- package/{esm2015/src/store/interface.js → esm2020/src/store/interface.mjs} +0 -0
- package/{esm2015/src/store/local-storage.service.js → esm2020/src/store/local-storage.service.mjs} +0 -0
- package/{esm2015/src/store/memory.service.js → esm2020/src/store/memory.service.mjs} +0 -0
- package/{esm2015/src/store/session-storage.service.js → esm2020/src/store/session-storage.service.mjs} +0 -0
- package/esm2020/src/token/base.interceptor.mjs +86 -0
- package/esm2020/src/token/helper.mjs +32 -0
- package/{esm2015/src/token/interface.js → esm2020/src/token/interface.mjs} +0 -0
- package/esm2020/src/token/jwt/jwt.guard.mjs +63 -0
- package/{esm2015/src/token/jwt/jwt.helper.js → esm2020/src/token/jwt/jwt.helper.mjs} +0 -0
- package/esm2020/src/token/jwt/jwt.interceptor.mjs +33 -0
- package/{esm2015/src/token/jwt/jwt.model.js → esm2020/src/token/jwt/jwt.model.mjs} +0 -0
- package/esm2020/src/token/simple/simple.guard.mjs +62 -0
- package/esm2020/src/token/simple/simple.interceptor.mjs +51 -0
- package/{esm2015/src/token/simple/simple.model.js → esm2020/src/token/simple/simple.model.mjs} +1 -1
- package/esm2020/src/token/token.service.mjs +92 -0
- package/fesm2015/{auth.js → auth.mjs} +80 -50
- package/fesm2015/auth.mjs.map +1 -0
- package/fesm2020/auth.mjs +717 -0
- package/fesm2020/auth.mjs.map +1 -0
- package/package.json +21 -9
- package/src/auth.module.d.ts +4 -0
- package/src/social/social.service.d.ts +3 -0
- package/src/token/base.interceptor.d.ts +3 -0
- package/src/token/jwt/jwt.guard.d.ts +3 -0
- package/src/token/jwt/jwt.interceptor.d.ts +3 -0
- package/src/token/simple/simple.guard.d.ts +3 -0
- package/src/token/simple/simple.interceptor.d.ts +3 -0
- package/src/token/simple/simple.model.d.ts +1 -1
- package/src/token/token.service.d.ts +4 -1
- package/auth.metadata.json +0 -1
- package/bundles/auth.umd.js +0 -1140
- package/bundles/auth.umd.js.map +0 -1
- package/esm2015/src/auth.module.js +0 -7
- package/esm2015/src/social/social.service.js +0 -96
- package/esm2015/src/token/base.interceptor.js +0 -84
- package/esm2015/src/token/helper.js +0 -30
- package/esm2015/src/token/jwt/jwt.guard.js +0 -63
- package/esm2015/src/token/jwt/jwt.interceptor.js +0 -30
- package/esm2015/src/token/simple/simple.guard.js +0 -62
- package/esm2015/src/token/simple/simple.interceptor.js +0 -48
- package/esm2015/src/token/token.service.js +0 -89
- package/fesm2015/auth.js.map +0 -1
package/bundles/auth.umd.js
DELETED
|
@@ -1,1140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license ng-alain(cipchk@qq.com) v12.4.2
|
|
3
|
-
* (c) 2020 cipchk https://ng-alain.com/
|
|
4
|
-
* License: MIT
|
|
5
|
-
*/
|
|
6
|
-
(function (global, factory) {
|
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@delon/util/config'), require('@angular/common/http')) :
|
|
8
|
-
typeof define === 'function' && define.amd ? define('@delon/auth', ['exports', '@angular/common', '@angular/core', '@angular/router', 'rxjs', 'rxjs/operators', '@delon/util/config', '@angular/common/http'], factory) :
|
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.delon = global.delon || {}, global.delon.auth = {}), global.ng.common, global.ng.core, global.ng.router, global.rxjs, global.rxjs.operators, global.config, global.ng.common.http));
|
|
10
|
-
})(this, (function (exports, common, i0, router, rxjs, operators, config, http) { 'use strict';
|
|
11
|
-
|
|
12
|
-
function _interopNamespace(e) {
|
|
13
|
-
if (e && e.__esModule) return e;
|
|
14
|
-
var n = Object.create(null);
|
|
15
|
-
if (e) {
|
|
16
|
-
Object.keys(e).forEach(function (k) {
|
|
17
|
-
if (k !== 'default') {
|
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return e[k]; }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
n["default"] = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
|
31
|
-
|
|
32
|
-
var AUTH_DEFAULT_CONFIG = {
|
|
33
|
-
store_key: "_token",
|
|
34
|
-
token_invalid_redirect: true,
|
|
35
|
-
token_exp_offset: 10,
|
|
36
|
-
token_send_key: "token",
|
|
37
|
-
token_send_template: '${token}',
|
|
38
|
-
token_send_place: 'header',
|
|
39
|
-
login_url: '/login',
|
|
40
|
-
ignores: [/\/login/, /assets\//, /passport\//],
|
|
41
|
-
allow_anonymous_key: "_allow_anonymous",
|
|
42
|
-
executeOtherInterceptors: true,
|
|
43
|
-
refreshTime: 3000,
|
|
44
|
-
refreshOffset: 6000
|
|
45
|
-
};
|
|
46
|
-
function mergeConfig(srv) {
|
|
47
|
-
return srv.merge('auth', AUTH_DEFAULT_CONFIG);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function DA_STORE_TOKEN_LOCAL_FACTORY() {
|
|
51
|
-
return new LocalStorageStore();
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* `localStorage` storage, **not lost after closing the browser**.
|
|
55
|
-
*
|
|
56
|
-
* ```ts
|
|
57
|
-
* // global-config.module.ts
|
|
58
|
-
* { provide: DA_STORE_TOKEN, useClass: LocalStorageStore }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
var LocalStorageStore = /** @class */ (function () {
|
|
62
|
-
function LocalStorageStore() {
|
|
63
|
-
}
|
|
64
|
-
LocalStorageStore.prototype.get = function (key) {
|
|
65
|
-
return JSON.parse(localStorage.getItem(key) || '{}') || {};
|
|
66
|
-
};
|
|
67
|
-
LocalStorageStore.prototype.set = function (key, value) {
|
|
68
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
69
|
-
return true;
|
|
70
|
-
};
|
|
71
|
-
LocalStorageStore.prototype.remove = function (key) {
|
|
72
|
-
localStorage.removeItem(key);
|
|
73
|
-
};
|
|
74
|
-
return LocalStorageStore;
|
|
75
|
-
}());
|
|
76
|
-
|
|
77
|
-
var DA_STORE_TOKEN = new i0.InjectionToken('AUTH_STORE_TOKEN', {
|
|
78
|
-
providedIn: 'root',
|
|
79
|
-
factory: DA_STORE_TOKEN_LOCAL_FACTORY
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
function DA_SERVICE_TOKEN_FACTORY() {
|
|
83
|
-
return new TokenService(i0.inject(config.AlainConfigService), i0.inject(DA_STORE_TOKEN));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 维护Token信息服务,[在线文档](https://ng-alain.com/auth)
|
|
87
|
-
*/
|
|
88
|
-
var TokenService = /** @class */ (function () {
|
|
89
|
-
function TokenService(configSrv, store) {
|
|
90
|
-
this.store = store;
|
|
91
|
-
this.refresh$ = new rxjs.Subject();
|
|
92
|
-
this.change$ = new rxjs.BehaviorSubject(null);
|
|
93
|
-
this._referrer = {};
|
|
94
|
-
this._options = mergeConfig(configSrv);
|
|
95
|
-
}
|
|
96
|
-
Object.defineProperty(TokenService.prototype, "refresh", {
|
|
97
|
-
get: function () {
|
|
98
|
-
this.builderRefresh();
|
|
99
|
-
return this.refresh$.pipe(operators.share());
|
|
100
|
-
},
|
|
101
|
-
enumerable: false,
|
|
102
|
-
configurable: true
|
|
103
|
-
});
|
|
104
|
-
Object.defineProperty(TokenService.prototype, "login_url", {
|
|
105
|
-
get: function () {
|
|
106
|
-
return this._options.login_url;
|
|
107
|
-
},
|
|
108
|
-
enumerable: false,
|
|
109
|
-
configurable: true
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(TokenService.prototype, "referrer", {
|
|
112
|
-
get: function () {
|
|
113
|
-
return this._referrer;
|
|
114
|
-
},
|
|
115
|
-
enumerable: false,
|
|
116
|
-
configurable: true
|
|
117
|
-
});
|
|
118
|
-
Object.defineProperty(TokenService.prototype, "options", {
|
|
119
|
-
get: function () {
|
|
120
|
-
return this._options;
|
|
121
|
-
},
|
|
122
|
-
enumerable: false,
|
|
123
|
-
configurable: true
|
|
124
|
-
});
|
|
125
|
-
TokenService.prototype.set = function (data) {
|
|
126
|
-
var res = this.store.set(this._options.store_key, data);
|
|
127
|
-
this.change$.next(data);
|
|
128
|
-
return res;
|
|
129
|
-
};
|
|
130
|
-
TokenService.prototype.get = function (type) {
|
|
131
|
-
var data = this.store.get(this._options.store_key);
|
|
132
|
-
return type ? Object.assign(new type(), data) : data;
|
|
133
|
-
};
|
|
134
|
-
TokenService.prototype.clear = function (options) {
|
|
135
|
-
if (options === void 0) { options = { onlyToken: false }; }
|
|
136
|
-
var data = null;
|
|
137
|
-
if (options.onlyToken === true) {
|
|
138
|
-
data = this.get();
|
|
139
|
-
data.token = "";
|
|
140
|
-
this.set(data);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
this.store.remove(this._options.store_key);
|
|
144
|
-
}
|
|
145
|
-
this.change$.next(data);
|
|
146
|
-
};
|
|
147
|
-
TokenService.prototype.change = function () {
|
|
148
|
-
return this.change$.pipe(operators.share());
|
|
149
|
-
};
|
|
150
|
-
TokenService.prototype.builderRefresh = function () {
|
|
151
|
-
var _this = this;
|
|
152
|
-
var _a = this._options, refreshTime = _a.refreshTime, refreshOffset = _a.refreshOffset;
|
|
153
|
-
this.cleanRefresh();
|
|
154
|
-
this.interval$ = rxjs.interval(refreshTime)
|
|
155
|
-
.pipe(operators.map(function () {
|
|
156
|
-
var item = _this.get();
|
|
157
|
-
var expired = item.expired || item.exp || 0;
|
|
158
|
-
if (expired <= 0) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
var curTime = new Date().valueOf() + refreshOffset;
|
|
162
|
-
return expired <= curTime ? item : null;
|
|
163
|
-
}), operators.filter(function (v) { return v != null; }))
|
|
164
|
-
.subscribe(function (res) { return _this.refresh$.next(res); });
|
|
165
|
-
};
|
|
166
|
-
TokenService.prototype.cleanRefresh = function () {
|
|
167
|
-
if (this.interval$ && !this.interval$.closed) {
|
|
168
|
-
this.interval$.unsubscribe();
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
TokenService.prototype.ngOnDestroy = function () {
|
|
172
|
-
this.cleanRefresh();
|
|
173
|
-
};
|
|
174
|
-
return TokenService;
|
|
175
|
-
}());
|
|
176
|
-
TokenService.decorators = [
|
|
177
|
-
{ type: i0.Injectable }
|
|
178
|
-
];
|
|
179
|
-
TokenService.ctorParameters = function () { return [
|
|
180
|
-
{ type: config.AlainConfigService },
|
|
181
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: [DA_STORE_TOKEN,] }] }
|
|
182
|
-
]; };
|
|
183
|
-
|
|
184
|
-
var DA_SERVICE_TOKEN = new i0.InjectionToken('DA_SERVICE_TOKEN', {
|
|
185
|
-
providedIn: 'root',
|
|
186
|
-
factory: DA_SERVICE_TOKEN_FACTORY
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
var OPENTYPE = '_delonAuthSocialType';
|
|
190
|
-
var HREFCALLBACK = '_delonAuthSocialCallbackByHref';
|
|
191
|
-
var SocialService = /** @class */ (function () {
|
|
192
|
-
function SocialService(tokenService, doc, router) {
|
|
193
|
-
this.tokenService = tokenService;
|
|
194
|
-
this.doc = doc;
|
|
195
|
-
this.router = router;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 跳转至登录页,若为 `type=window` 时,返回值是 `Observable<ITokenModel>`
|
|
199
|
-
*
|
|
200
|
-
* @param url 获取授权地址
|
|
201
|
-
* @param callback 当 `type=href` 成功时的回调路由地址
|
|
202
|
-
* @param options.type 打开方式,默认 `window`
|
|
203
|
-
* @param options.windowFeatures 等同 `window.open` 的 `features` 参数值
|
|
204
|
-
*/
|
|
205
|
-
SocialService.prototype.login = function (url, callback, options) {
|
|
206
|
-
var _this = this;
|
|
207
|
-
if (callback === void 0) { callback = '/'; }
|
|
208
|
-
if (options === void 0) { options = {}; }
|
|
209
|
-
options = Object.assign({ type: 'window', windowFeatures: 'location=yes,height=570,width=520,scrollbars=yes,status=yes' }, options);
|
|
210
|
-
localStorage.setItem(OPENTYPE, options.type);
|
|
211
|
-
localStorage.setItem(HREFCALLBACK, callback);
|
|
212
|
-
if (options.type === 'href') {
|
|
213
|
-
this.doc.location.href = url;
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
this._win = window.open(url, '_blank', options.windowFeatures);
|
|
217
|
-
this._winTime = setInterval(function () {
|
|
218
|
-
if (_this._win && _this._win.closed) {
|
|
219
|
-
_this.ngOnDestroy();
|
|
220
|
-
var model = _this.tokenService.get();
|
|
221
|
-
if (model && !model.token)
|
|
222
|
-
model = null;
|
|
223
|
-
// 触发变更通知
|
|
224
|
-
if (model) {
|
|
225
|
-
_this.tokenService.set(model);
|
|
226
|
-
}
|
|
227
|
-
_this.observer.next(model);
|
|
228
|
-
_this.observer.complete();
|
|
229
|
-
}
|
|
230
|
-
}, 100);
|
|
231
|
-
return new rxjs.Observable(function (observer) {
|
|
232
|
-
_this.observer = observer;
|
|
233
|
-
});
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* 授权成功后的回调处理
|
|
237
|
-
*
|
|
238
|
-
* @param rawData 指定回调认证信息,为空时从根据当前URL解析
|
|
239
|
-
*/
|
|
240
|
-
SocialService.prototype.callback = function (rawData) {
|
|
241
|
-
// from uri
|
|
242
|
-
if (!rawData && this.router.url.indexOf('?') === -1) {
|
|
243
|
-
throw new Error("url muse contain a ?");
|
|
244
|
-
}
|
|
245
|
-
// parse
|
|
246
|
-
var data = { token: "" };
|
|
247
|
-
if (typeof rawData === 'string') {
|
|
248
|
-
var rightUrl = rawData.split('?')[1].split('#')[0];
|
|
249
|
-
data = this.router.parseUrl("./?" + rightUrl).queryParams;
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
data = rawData;
|
|
253
|
-
}
|
|
254
|
-
if (!data || !data.token)
|
|
255
|
-
throw new Error("invalide token data");
|
|
256
|
-
this.tokenService.set(data);
|
|
257
|
-
var url = localStorage.getItem(HREFCALLBACK) || '/';
|
|
258
|
-
localStorage.removeItem(HREFCALLBACK);
|
|
259
|
-
var type = localStorage.getItem(OPENTYPE);
|
|
260
|
-
localStorage.removeItem(OPENTYPE);
|
|
261
|
-
if (type === 'window') {
|
|
262
|
-
window.close();
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
this.router.navigateByUrl(url);
|
|
266
|
-
}
|
|
267
|
-
return data;
|
|
268
|
-
};
|
|
269
|
-
SocialService.prototype.ngOnDestroy = function () {
|
|
270
|
-
clearInterval(this._winTime);
|
|
271
|
-
this._winTime = null;
|
|
272
|
-
};
|
|
273
|
-
return SocialService;
|
|
274
|
-
}());
|
|
275
|
-
SocialService.decorators = [
|
|
276
|
-
{ type: i0.Injectable }
|
|
277
|
-
];
|
|
278
|
-
SocialService.ctorParameters = function () { return [
|
|
279
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: [DA_SERVICE_TOKEN,] }] },
|
|
280
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: [common.DOCUMENT,] }] },
|
|
281
|
-
{ type: router.Router }
|
|
282
|
-
]; };
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* 内存存储,关掉浏览器标签后**丢失**。
|
|
286
|
-
*
|
|
287
|
-
* ```ts
|
|
288
|
-
* // global-config.module.ts
|
|
289
|
-
* { provide: DA_STORE_TOKEN, useClass: MemoryStore }
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
var MemoryStore = /** @class */ (function () {
|
|
293
|
-
function MemoryStore() {
|
|
294
|
-
this.cache = {};
|
|
295
|
-
}
|
|
296
|
-
MemoryStore.prototype.get = function (key) {
|
|
297
|
-
return this.cache[key] || {};
|
|
298
|
-
};
|
|
299
|
-
MemoryStore.prototype.set = function (key, value) {
|
|
300
|
-
this.cache[key] = value;
|
|
301
|
-
return true;
|
|
302
|
-
};
|
|
303
|
-
MemoryStore.prototype.remove = function (key) {
|
|
304
|
-
this.cache[key] = null;
|
|
305
|
-
};
|
|
306
|
-
return MemoryStore;
|
|
307
|
-
}());
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* `sessionStorage` storage, **lost after closing the browser**.
|
|
311
|
-
*
|
|
312
|
-
* ```ts
|
|
313
|
-
* // global-config.module.ts
|
|
314
|
-
* { provide: DA_STORE_TOKEN, useClass: SessionStorageStore }
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
var SessionStorageStore = /** @class */ (function () {
|
|
318
|
-
function SessionStorageStore() {
|
|
319
|
-
}
|
|
320
|
-
SessionStorageStore.prototype.get = function (key) {
|
|
321
|
-
return JSON.parse(sessionStorage.getItem(key) || '{}') || {};
|
|
322
|
-
};
|
|
323
|
-
SessionStorageStore.prototype.set = function (key, value) {
|
|
324
|
-
sessionStorage.setItem(key, JSON.stringify(value));
|
|
325
|
-
return true;
|
|
326
|
-
};
|
|
327
|
-
SessionStorageStore.prototype.remove = function (key) {
|
|
328
|
-
sessionStorage.removeItem(key);
|
|
329
|
-
};
|
|
330
|
-
return SessionStorageStore;
|
|
331
|
-
}());
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* `cookie` storage
|
|
335
|
-
*
|
|
336
|
-
* ```ts
|
|
337
|
-
* // global-config.module.ts
|
|
338
|
-
* { provide: DA_STORE_TOKEN, useClass: CookieStorageStore, deps: [CookieService] }
|
|
339
|
-
* ```
|
|
340
|
-
*/
|
|
341
|
-
var CookieStorageStore = /** @class */ (function () {
|
|
342
|
-
function CookieStorageStore(srv) {
|
|
343
|
-
this.srv = srv;
|
|
344
|
-
}
|
|
345
|
-
CookieStorageStore.prototype.get = function (key) {
|
|
346
|
-
return JSON.parse(this.srv.get(key) || '{}') || {};
|
|
347
|
-
};
|
|
348
|
-
CookieStorageStore.prototype.set = function (key, value) {
|
|
349
|
-
this.srv.put(key, value != null ? JSON.stringify(value) : '{}');
|
|
350
|
-
return true;
|
|
351
|
-
};
|
|
352
|
-
CookieStorageStore.prototype.remove = function (key) {
|
|
353
|
-
this.srv.remove(key);
|
|
354
|
-
};
|
|
355
|
-
return CookieStorageStore;
|
|
356
|
-
}());
|
|
357
|
-
|
|
358
|
-
/*! *****************************************************************************
|
|
359
|
-
Copyright (c) Microsoft Corporation.
|
|
360
|
-
|
|
361
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
362
|
-
purpose with or without fee is hereby granted.
|
|
363
|
-
|
|
364
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
365
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
366
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
367
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
368
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
369
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
370
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
371
|
-
***************************************************************************** */
|
|
372
|
-
/* global Reflect, Promise */
|
|
373
|
-
var extendStatics = function (d, b) {
|
|
374
|
-
extendStatics = Object.setPrototypeOf ||
|
|
375
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
376
|
-
function (d, b) { for (var p in b)
|
|
377
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
378
|
-
d[p] = b[p]; };
|
|
379
|
-
return extendStatics(d, b);
|
|
380
|
-
};
|
|
381
|
-
function __extends(d, b) {
|
|
382
|
-
if (typeof b !== "function" && b !== null)
|
|
383
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
384
|
-
extendStatics(d, b);
|
|
385
|
-
function __() { this.constructor = d; }
|
|
386
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
387
|
-
}
|
|
388
|
-
var __assign = function () {
|
|
389
|
-
__assign = Object.assign || function __assign(t) {
|
|
390
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
391
|
-
s = arguments[i];
|
|
392
|
-
for (var p in s)
|
|
393
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
394
|
-
t[p] = s[p];
|
|
395
|
-
}
|
|
396
|
-
return t;
|
|
397
|
-
};
|
|
398
|
-
return __assign.apply(this, arguments);
|
|
399
|
-
};
|
|
400
|
-
function __rest(s, e) {
|
|
401
|
-
var t = {};
|
|
402
|
-
for (var p in s)
|
|
403
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
404
|
-
t[p] = s[p];
|
|
405
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
406
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
407
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
408
|
-
t[p[i]] = s[p[i]];
|
|
409
|
-
}
|
|
410
|
-
return t;
|
|
411
|
-
}
|
|
412
|
-
function __decorate(decorators, target, key, desc) {
|
|
413
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
414
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
415
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
416
|
-
else
|
|
417
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
418
|
-
if (d = decorators[i])
|
|
419
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
420
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
421
|
-
}
|
|
422
|
-
function __param(paramIndex, decorator) {
|
|
423
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
424
|
-
}
|
|
425
|
-
function __metadata(metadataKey, metadataValue) {
|
|
426
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
427
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
428
|
-
}
|
|
429
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
430
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
431
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
432
|
-
function fulfilled(value) { try {
|
|
433
|
-
step(generator.next(value));
|
|
434
|
-
}
|
|
435
|
-
catch (e) {
|
|
436
|
-
reject(e);
|
|
437
|
-
} }
|
|
438
|
-
function rejected(value) { try {
|
|
439
|
-
step(generator["throw"](value));
|
|
440
|
-
}
|
|
441
|
-
catch (e) {
|
|
442
|
-
reject(e);
|
|
443
|
-
} }
|
|
444
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
445
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
function __generator(thisArg, body) {
|
|
449
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
450
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
451
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
452
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
453
|
-
function step(op) {
|
|
454
|
-
if (f)
|
|
455
|
-
throw new TypeError("Generator is already executing.");
|
|
456
|
-
while (_)
|
|
457
|
-
try {
|
|
458
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
459
|
-
return t;
|
|
460
|
-
if (y = 0, t)
|
|
461
|
-
op = [op[0] & 2, t.value];
|
|
462
|
-
switch (op[0]) {
|
|
463
|
-
case 0:
|
|
464
|
-
case 1:
|
|
465
|
-
t = op;
|
|
466
|
-
break;
|
|
467
|
-
case 4:
|
|
468
|
-
_.label++;
|
|
469
|
-
return { value: op[1], done: false };
|
|
470
|
-
case 5:
|
|
471
|
-
_.label++;
|
|
472
|
-
y = op[1];
|
|
473
|
-
op = [0];
|
|
474
|
-
continue;
|
|
475
|
-
case 7:
|
|
476
|
-
op = _.ops.pop();
|
|
477
|
-
_.trys.pop();
|
|
478
|
-
continue;
|
|
479
|
-
default:
|
|
480
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
481
|
-
_ = 0;
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
485
|
-
_.label = op[1];
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
489
|
-
_.label = t[1];
|
|
490
|
-
t = op;
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
if (t && _.label < t[2]) {
|
|
494
|
-
_.label = t[2];
|
|
495
|
-
_.ops.push(op);
|
|
496
|
-
break;
|
|
497
|
-
}
|
|
498
|
-
if (t[2])
|
|
499
|
-
_.ops.pop();
|
|
500
|
-
_.trys.pop();
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
op = body.call(thisArg, _);
|
|
504
|
-
}
|
|
505
|
-
catch (e) {
|
|
506
|
-
op = [6, e];
|
|
507
|
-
y = 0;
|
|
508
|
-
}
|
|
509
|
-
finally {
|
|
510
|
-
f = t = 0;
|
|
511
|
-
}
|
|
512
|
-
if (op[0] & 5)
|
|
513
|
-
throw op[1];
|
|
514
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
518
|
-
if (k2 === undefined)
|
|
519
|
-
k2 = k;
|
|
520
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
521
|
-
}) : (function (o, m, k, k2) {
|
|
522
|
-
if (k2 === undefined)
|
|
523
|
-
k2 = k;
|
|
524
|
-
o[k2] = m[k];
|
|
525
|
-
});
|
|
526
|
-
function __exportStar(m, o) {
|
|
527
|
-
for (var p in m)
|
|
528
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
529
|
-
__createBinding(o, m, p);
|
|
530
|
-
}
|
|
531
|
-
function __values(o) {
|
|
532
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
533
|
-
if (m)
|
|
534
|
-
return m.call(o);
|
|
535
|
-
if (o && typeof o.length === "number")
|
|
536
|
-
return {
|
|
537
|
-
next: function () {
|
|
538
|
-
if (o && i >= o.length)
|
|
539
|
-
o = void 0;
|
|
540
|
-
return { value: o && o[i++], done: !o };
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
544
|
-
}
|
|
545
|
-
function __read(o, n) {
|
|
546
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
547
|
-
if (!m)
|
|
548
|
-
return o;
|
|
549
|
-
var i = m.call(o), r, ar = [], e;
|
|
550
|
-
try {
|
|
551
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
552
|
-
ar.push(r.value);
|
|
553
|
-
}
|
|
554
|
-
catch (error) {
|
|
555
|
-
e = { error: error };
|
|
556
|
-
}
|
|
557
|
-
finally {
|
|
558
|
-
try {
|
|
559
|
-
if (r && !r.done && (m = i["return"]))
|
|
560
|
-
m.call(i);
|
|
561
|
-
}
|
|
562
|
-
finally {
|
|
563
|
-
if (e)
|
|
564
|
-
throw e.error;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return ar;
|
|
568
|
-
}
|
|
569
|
-
/** @deprecated */
|
|
570
|
-
function __spread() {
|
|
571
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
572
|
-
ar = ar.concat(__read(arguments[i]));
|
|
573
|
-
return ar;
|
|
574
|
-
}
|
|
575
|
-
/** @deprecated */
|
|
576
|
-
function __spreadArrays() {
|
|
577
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
578
|
-
s += arguments[i].length;
|
|
579
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
580
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
581
|
-
r[k] = a[j];
|
|
582
|
-
return r;
|
|
583
|
-
}
|
|
584
|
-
function __spreadArray(to, from, pack) {
|
|
585
|
-
if (pack || arguments.length === 2)
|
|
586
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
587
|
-
if (ar || !(i in from)) {
|
|
588
|
-
if (!ar)
|
|
589
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
590
|
-
ar[i] = from[i];
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
594
|
-
}
|
|
595
|
-
function __await(v) {
|
|
596
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
597
|
-
}
|
|
598
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
599
|
-
if (!Symbol.asyncIterator)
|
|
600
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
601
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
602
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
603
|
-
function verb(n) { if (g[n])
|
|
604
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
605
|
-
function resume(n, v) { try {
|
|
606
|
-
step(g[n](v));
|
|
607
|
-
}
|
|
608
|
-
catch (e) {
|
|
609
|
-
settle(q[0][3], e);
|
|
610
|
-
} }
|
|
611
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
612
|
-
function fulfill(value) { resume("next", value); }
|
|
613
|
-
function reject(value) { resume("throw", value); }
|
|
614
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
615
|
-
resume(q[0][0], q[0][1]); }
|
|
616
|
-
}
|
|
617
|
-
function __asyncDelegator(o) {
|
|
618
|
-
var i, p;
|
|
619
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
620
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
621
|
-
}
|
|
622
|
-
function __asyncValues(o) {
|
|
623
|
-
if (!Symbol.asyncIterator)
|
|
624
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
625
|
-
var m = o[Symbol.asyncIterator], i;
|
|
626
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
627
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
628
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
629
|
-
}
|
|
630
|
-
function __makeTemplateObject(cooked, raw) {
|
|
631
|
-
if (Object.defineProperty) {
|
|
632
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
cooked.raw = raw;
|
|
636
|
-
}
|
|
637
|
-
return cooked;
|
|
638
|
-
}
|
|
639
|
-
;
|
|
640
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
641
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
642
|
-
}) : function (o, v) {
|
|
643
|
-
o["default"] = v;
|
|
644
|
-
};
|
|
645
|
-
function __importStar(mod) {
|
|
646
|
-
if (mod && mod.__esModule)
|
|
647
|
-
return mod;
|
|
648
|
-
var result = {};
|
|
649
|
-
if (mod != null)
|
|
650
|
-
for (var k in mod)
|
|
651
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
652
|
-
__createBinding(result, mod, k);
|
|
653
|
-
__setModuleDefault(result, mod);
|
|
654
|
-
return result;
|
|
655
|
-
}
|
|
656
|
-
function __importDefault(mod) {
|
|
657
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
658
|
-
}
|
|
659
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
660
|
-
if (kind === "a" && !f)
|
|
661
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
662
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
663
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
664
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
665
|
-
}
|
|
666
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
667
|
-
if (kind === "m")
|
|
668
|
-
throw new TypeError("Private method is not writable");
|
|
669
|
-
if (kind === "a" && !f)
|
|
670
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
671
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
672
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
673
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
function CheckSimple(model) {
|
|
677
|
-
return model != null && typeof model.token === 'string' && model.token.length > 0;
|
|
678
|
-
}
|
|
679
|
-
function CheckJwt(model, offset) {
|
|
680
|
-
try {
|
|
681
|
-
return model != null && !!model.token && !model.isExpired(offset);
|
|
682
|
-
}
|
|
683
|
-
catch (err) {
|
|
684
|
-
console.warn(err.message + ", jump to login_url");
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
function ToLogin(options, injector, url) {
|
|
689
|
-
var router$1 = injector.get(router.Router);
|
|
690
|
-
injector.get(DA_SERVICE_TOKEN).referrer.url = url || router$1.url;
|
|
691
|
-
if (options.token_invalid_redirect === true) {
|
|
692
|
-
setTimeout(function () {
|
|
693
|
-
if (/^https?:\/\//g.test(options.login_url)) {
|
|
694
|
-
injector.get(common.DOCUMENT).location.href = options.login_url;
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
router$1.navigate([options.login_url]);
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
var HttpAuthInterceptorHandler = /** @class */ (function () {
|
|
704
|
-
function HttpAuthInterceptorHandler(next, interceptor) {
|
|
705
|
-
this.next = next;
|
|
706
|
-
this.interceptor = interceptor;
|
|
707
|
-
}
|
|
708
|
-
HttpAuthInterceptorHandler.prototype.handle = function (req) {
|
|
709
|
-
return this.interceptor.intercept(req, this.next);
|
|
710
|
-
};
|
|
711
|
-
return HttpAuthInterceptorHandler;
|
|
712
|
-
}());
|
|
713
|
-
var BaseInterceptor = /** @class */ (function () {
|
|
714
|
-
function BaseInterceptor(injector) {
|
|
715
|
-
this.injector = injector;
|
|
716
|
-
}
|
|
717
|
-
BaseInterceptor.prototype.intercept = function (req, next) {
|
|
718
|
-
var e_1, _a;
|
|
719
|
-
var options = mergeConfig(this.injector.get(config.AlainConfigService));
|
|
720
|
-
if (Array.isArray(options.ignores)) {
|
|
721
|
-
try {
|
|
722
|
-
for (var _b = __values(options.ignores), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
723
|
-
var item = _c.value;
|
|
724
|
-
if (item.test(req.url))
|
|
725
|
-
return next.handle(req);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
729
|
-
finally {
|
|
730
|
-
try {
|
|
731
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
732
|
-
}
|
|
733
|
-
finally { if (e_1) throw e_1.error; }
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
var ingoreKey = options.allow_anonymous_key;
|
|
737
|
-
var ingored = false;
|
|
738
|
-
var params = req.params;
|
|
739
|
-
var url = req.url;
|
|
740
|
-
if (req.params.has(ingoreKey)) {
|
|
741
|
-
params = req.params.delete(ingoreKey);
|
|
742
|
-
ingored = true;
|
|
743
|
-
}
|
|
744
|
-
var urlArr = req.url.split('?');
|
|
745
|
-
if (urlArr.length > 1) {
|
|
746
|
-
var queryStringParams = new http.HttpParams({ fromString: urlArr[1] });
|
|
747
|
-
if (queryStringParams.has(ingoreKey)) {
|
|
748
|
-
var queryString = queryStringParams.delete(ingoreKey).toString();
|
|
749
|
-
url = queryString.length > 0 ? urlArr[0] + "?" + queryString : urlArr[0];
|
|
750
|
-
ingored = true;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
if (ingored) {
|
|
754
|
-
return next.handle(req.clone({ params: params, url: url }));
|
|
755
|
-
}
|
|
756
|
-
if (this.isAuth(options)) {
|
|
757
|
-
req = this.setReq(req, options);
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
760
|
-
ToLogin(options, this.injector);
|
|
761
|
-
// Interrupt Http request, so need to generate a new Observable
|
|
762
|
-
var err$_1 = new rxjs.Observable(function (observer) {
|
|
763
|
-
var res = new http.HttpErrorResponse({
|
|
764
|
-
url: req.url,
|
|
765
|
-
headers: req.headers,
|
|
766
|
-
status: 401,
|
|
767
|
-
statusText: "\u6765\u81EA @delon/auth \u7684\u62E6\u622A\uFF0C\u6240\u8BF7\u6C42URL\u672A\u6388\u6743\uFF0C\u82E5\u662F\u767B\u5F55API\u53EF\u52A0\u5165 [url?_allow_anonymous=true] \u6765\u8868\u793A\u5FFD\u7565\u6821\u9A8C\uFF0C\u66F4\u591A\u65B9\u6CD5\u8BF7\u53C2\u8003\uFF1A https://ng-alain.com/auth/getting-started#AlainAuthConfig\nThe interception from @delon/auth, the requested URL is not authorized. If the login API can add [url?_allow_anonymous=true] to ignore the check, please refer to: https://ng-alain.com/auth/getting-started#AlainAuthConfig"
|
|
768
|
-
});
|
|
769
|
-
observer.error(res);
|
|
770
|
-
});
|
|
771
|
-
if (options.executeOtherInterceptors) {
|
|
772
|
-
var interceptors = this.injector.get(http.HTTP_INTERCEPTORS, []);
|
|
773
|
-
var lastInterceptors = interceptors.slice(interceptors.indexOf(this) + 1);
|
|
774
|
-
if (lastInterceptors.length > 0) {
|
|
775
|
-
var chain = lastInterceptors.reduceRight(function (_next, _interceptor) { return new HttpAuthInterceptorHandler(_next, _interceptor); }, {
|
|
776
|
-
handle: function (_) { return err$_1; }
|
|
777
|
-
});
|
|
778
|
-
return chain.handle(req);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return err$_1;
|
|
782
|
-
}
|
|
783
|
-
return next.handle(req);
|
|
784
|
-
};
|
|
785
|
-
return BaseInterceptor;
|
|
786
|
-
}());
|
|
787
|
-
BaseInterceptor.decorators = [
|
|
788
|
-
{ type: i0.Injectable }
|
|
789
|
-
];
|
|
790
|
-
BaseInterceptor.ctorParameters = function () { return [
|
|
791
|
-
{ type: i0.Injector, decorators: [{ type: i0.Optional }] }
|
|
792
|
-
]; };
|
|
793
|
-
|
|
794
|
-
function urlBase64Decode(str) {
|
|
795
|
-
var output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
796
|
-
switch (output.length % 4) {
|
|
797
|
-
case 0: {
|
|
798
|
-
break;
|
|
799
|
-
}
|
|
800
|
-
case 2: {
|
|
801
|
-
output += '==';
|
|
802
|
-
break;
|
|
803
|
-
}
|
|
804
|
-
case 3: {
|
|
805
|
-
output += '=';
|
|
806
|
-
break;
|
|
807
|
-
}
|
|
808
|
-
default: {
|
|
809
|
-
throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
return b64DecodeUnicode(output);
|
|
813
|
-
}
|
|
814
|
-
function b64decode(str) {
|
|
815
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
816
|
-
var output = '';
|
|
817
|
-
str = String(str).replace(/=+$/, '');
|
|
818
|
-
for (
|
|
819
|
-
// initialize result and counters
|
|
820
|
-
var bc = 0, bs = void 0, buffer = void 0, idx = 0;
|
|
821
|
-
// get next character
|
|
822
|
-
(buffer = str.charAt(idx++));
|
|
823
|
-
// character found in table? initialize bit storage and add its ascii value;
|
|
824
|
-
~buffer &&
|
|
825
|
-
((bs = bc % 4 ? bs * 64 + buffer : buffer),
|
|
826
|
-
// and if not first of each 4 characters,
|
|
827
|
-
// convert the first 8 bits to one ascii character
|
|
828
|
-
bc++ % 4)
|
|
829
|
-
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
|
|
830
|
-
: 0) {
|
|
831
|
-
// try to find character in table (0-63, not found => -1)
|
|
832
|
-
buffer = chars.indexOf(buffer);
|
|
833
|
-
}
|
|
834
|
-
return output;
|
|
835
|
-
}
|
|
836
|
-
// https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
|
837
|
-
function b64DecodeUnicode(str) {
|
|
838
|
-
return decodeURIComponent(Array.prototype.map
|
|
839
|
-
.call(b64decode(str), function (c) {
|
|
840
|
-
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
841
|
-
})
|
|
842
|
-
.join(''));
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
var JWTTokenModel = /** @class */ (function () {
|
|
846
|
-
function JWTTokenModel() {
|
|
847
|
-
}
|
|
848
|
-
Object.defineProperty(JWTTokenModel.prototype, "payload", {
|
|
849
|
-
/**
|
|
850
|
-
* 获取载荷信息
|
|
851
|
-
*/
|
|
852
|
-
get: function () {
|
|
853
|
-
var parts = (this.token || '').split('.');
|
|
854
|
-
if (parts.length !== 3)
|
|
855
|
-
throw new Error('JWT must have 3 parts');
|
|
856
|
-
var decoded = urlBase64Decode(parts[1]);
|
|
857
|
-
return JSON.parse(decoded);
|
|
858
|
-
},
|
|
859
|
-
enumerable: false,
|
|
860
|
-
configurable: true
|
|
861
|
-
});
|
|
862
|
-
Object.defineProperty(JWTTokenModel.prototype, "exp", {
|
|
863
|
-
/**
|
|
864
|
-
* 获取过期时间戳(单位:ms)
|
|
865
|
-
*/
|
|
866
|
-
get: function () {
|
|
867
|
-
var decoded = this.payload;
|
|
868
|
-
if (!decoded.hasOwnProperty('exp'))
|
|
869
|
-
return null;
|
|
870
|
-
var date = new Date(0);
|
|
871
|
-
date.setUTCSeconds(decoded.exp);
|
|
872
|
-
return date.valueOf();
|
|
873
|
-
},
|
|
874
|
-
enumerable: false,
|
|
875
|
-
configurable: true
|
|
876
|
-
});
|
|
877
|
-
/**
|
|
878
|
-
* 检查Token是否过期,当`payload` 包含 `exp` 字段时有效,若无 `exp` 字段直接返回 `null`
|
|
879
|
-
*
|
|
880
|
-
* @param offsetSeconds 偏移量
|
|
881
|
-
*/
|
|
882
|
-
JWTTokenModel.prototype.isExpired = function (offsetSeconds) {
|
|
883
|
-
if (offsetSeconds === void 0) { offsetSeconds = 0; }
|
|
884
|
-
var exp = this.exp;
|
|
885
|
-
if (exp == null)
|
|
886
|
-
return null;
|
|
887
|
-
return !(exp > new Date().valueOf() + offsetSeconds * 1000);
|
|
888
|
-
};
|
|
889
|
-
return JWTTokenModel;
|
|
890
|
-
}());
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* JWT 拦截器
|
|
894
|
-
*
|
|
895
|
-
* ```
|
|
896
|
-
* // app.module.ts
|
|
897
|
-
* { provide: HTTP_INTERCEPTORS, useClass: JWTInterceptor, multi: true}
|
|
898
|
-
* ```
|
|
899
|
-
*/
|
|
900
|
-
var JWTInterceptor = /** @class */ (function (_super) {
|
|
901
|
-
__extends(JWTInterceptor, _super);
|
|
902
|
-
function JWTInterceptor() {
|
|
903
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
904
|
-
}
|
|
905
|
-
JWTInterceptor.prototype.isAuth = function (options) {
|
|
906
|
-
this.model = this.injector.get(DA_SERVICE_TOKEN).get(JWTTokenModel);
|
|
907
|
-
return CheckJwt(this.model, options.token_exp_offset);
|
|
908
|
-
};
|
|
909
|
-
JWTInterceptor.prototype.setReq = function (req, _options) {
|
|
910
|
-
return req.clone({
|
|
911
|
-
setHeaders: {
|
|
912
|
-
Authorization: "Bearer " + this.model.token
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
};
|
|
916
|
-
return JWTInterceptor;
|
|
917
|
-
}(BaseInterceptor));
|
|
918
|
-
JWTInterceptor.decorators = [
|
|
919
|
-
{ type: i0.Injectable }
|
|
920
|
-
];
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* JWT 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
|
|
924
|
-
*
|
|
925
|
-
* ```ts
|
|
926
|
-
* data: {
|
|
927
|
-
* path: 'home',
|
|
928
|
-
* canActivate: [ JWTGuard ]
|
|
929
|
-
* },
|
|
930
|
-
* {
|
|
931
|
-
* path: 'my',
|
|
932
|
-
* canActivateChild: [JWTGuard],
|
|
933
|
-
* children: [
|
|
934
|
-
* { path: 'profile', component: MockComponent }
|
|
935
|
-
* ],
|
|
936
|
-
* },
|
|
937
|
-
* ```
|
|
938
|
-
*/
|
|
939
|
-
var JWTGuard = /** @class */ (function () {
|
|
940
|
-
function JWTGuard(srv, injector) {
|
|
941
|
-
this.srv = srv;
|
|
942
|
-
this.injector = injector;
|
|
943
|
-
}
|
|
944
|
-
Object.defineProperty(JWTGuard.prototype, "cog", {
|
|
945
|
-
get: function () {
|
|
946
|
-
return this.srv.options;
|
|
947
|
-
},
|
|
948
|
-
enumerable: false,
|
|
949
|
-
configurable: true
|
|
950
|
-
});
|
|
951
|
-
JWTGuard.prototype.process = function () {
|
|
952
|
-
var res = CheckJwt(this.srv.get(JWTTokenModel), this.cog.token_exp_offset);
|
|
953
|
-
if (!res) {
|
|
954
|
-
ToLogin(this.cog, this.injector, this.url);
|
|
955
|
-
}
|
|
956
|
-
return res;
|
|
957
|
-
};
|
|
958
|
-
// lazy loading
|
|
959
|
-
JWTGuard.prototype.canLoad = function (route, _segments) {
|
|
960
|
-
this.url = route.path;
|
|
961
|
-
return this.process();
|
|
962
|
-
};
|
|
963
|
-
// all children route
|
|
964
|
-
JWTGuard.prototype.canActivateChild = function (_childRoute, state) {
|
|
965
|
-
this.url = state.url;
|
|
966
|
-
return this.process();
|
|
967
|
-
};
|
|
968
|
-
// route
|
|
969
|
-
JWTGuard.prototype.canActivate = function (_route, state) {
|
|
970
|
-
this.url = state.url;
|
|
971
|
-
return this.process();
|
|
972
|
-
};
|
|
973
|
-
return JWTGuard;
|
|
974
|
-
}());
|
|
975
|
-
JWTGuard.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function JWTGuard_Factory() { return new JWTGuard(i0__namespace.ɵɵinject(DA_SERVICE_TOKEN), i0__namespace.ɵɵinject(i0__namespace.INJECTOR)); }, token: JWTGuard, providedIn: "root" });
|
|
976
|
-
JWTGuard.decorators = [
|
|
977
|
-
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
978
|
-
];
|
|
979
|
-
JWTGuard.ctorParameters = function () { return [
|
|
980
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: [DA_SERVICE_TOKEN,] }] },
|
|
981
|
-
{ type: i0.Injector }
|
|
982
|
-
]; };
|
|
983
|
-
|
|
984
|
-
var SimpleTokenModel = /** @class */ (function () {
|
|
985
|
-
function SimpleTokenModel() {
|
|
986
|
-
}
|
|
987
|
-
return SimpleTokenModel;
|
|
988
|
-
}());
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* Simple 拦截器
|
|
992
|
-
*
|
|
993
|
-
* ```
|
|
994
|
-
* // app.module.ts
|
|
995
|
-
* { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true}
|
|
996
|
-
* ```
|
|
997
|
-
*/
|
|
998
|
-
var SimpleInterceptor = /** @class */ (function (_super) {
|
|
999
|
-
__extends(SimpleInterceptor, _super);
|
|
1000
|
-
function SimpleInterceptor() {
|
|
1001
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1002
|
-
}
|
|
1003
|
-
SimpleInterceptor.prototype.isAuth = function (_options) {
|
|
1004
|
-
this.model = this.injector.get(DA_SERVICE_TOKEN).get();
|
|
1005
|
-
return CheckSimple(this.model);
|
|
1006
|
-
};
|
|
1007
|
-
SimpleInterceptor.prototype.setReq = function (req, options) {
|
|
1008
|
-
var _this = this;
|
|
1009
|
-
var token_send_template = options.token_send_template, token_send_key = options.token_send_key;
|
|
1010
|
-
var token = token_send_template.replace(/\$\{([\w]+)\}/g, function (_, g) { return _this.model[g]; });
|
|
1011
|
-
switch (options.token_send_place) {
|
|
1012
|
-
case 'header':
|
|
1013
|
-
var obj = {};
|
|
1014
|
-
obj[token_send_key] = token;
|
|
1015
|
-
req = req.clone({
|
|
1016
|
-
setHeaders: obj
|
|
1017
|
-
});
|
|
1018
|
-
break;
|
|
1019
|
-
case 'body':
|
|
1020
|
-
var body = req.body || {};
|
|
1021
|
-
body[token_send_key] = token;
|
|
1022
|
-
req = req.clone({
|
|
1023
|
-
body: body
|
|
1024
|
-
});
|
|
1025
|
-
break;
|
|
1026
|
-
case 'url':
|
|
1027
|
-
req = req.clone({
|
|
1028
|
-
params: req.params.append(token_send_key, token)
|
|
1029
|
-
});
|
|
1030
|
-
break;
|
|
1031
|
-
}
|
|
1032
|
-
return req;
|
|
1033
|
-
};
|
|
1034
|
-
return SimpleInterceptor;
|
|
1035
|
-
}(BaseInterceptor));
|
|
1036
|
-
SimpleInterceptor.decorators = [
|
|
1037
|
-
{ type: i0.Injectable }
|
|
1038
|
-
];
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
|
|
1042
|
-
*
|
|
1043
|
-
* ```ts
|
|
1044
|
-
* data: {
|
|
1045
|
-
* path: 'home',
|
|
1046
|
-
* canActivate: [ SimpleGuard ]
|
|
1047
|
-
* },
|
|
1048
|
-
* {
|
|
1049
|
-
* path: 'my',
|
|
1050
|
-
* canActivateChild: [SimpleGuard],
|
|
1051
|
-
* children: [
|
|
1052
|
-
* { path: 'profile', component: MockComponent }
|
|
1053
|
-
* ],
|
|
1054
|
-
* },
|
|
1055
|
-
* ```
|
|
1056
|
-
*/
|
|
1057
|
-
var SimpleGuard = /** @class */ (function () {
|
|
1058
|
-
function SimpleGuard(srv, injector) {
|
|
1059
|
-
this.srv = srv;
|
|
1060
|
-
this.injector = injector;
|
|
1061
|
-
}
|
|
1062
|
-
Object.defineProperty(SimpleGuard.prototype, "cog", {
|
|
1063
|
-
get: function () {
|
|
1064
|
-
return this.srv.options;
|
|
1065
|
-
},
|
|
1066
|
-
enumerable: false,
|
|
1067
|
-
configurable: true
|
|
1068
|
-
});
|
|
1069
|
-
SimpleGuard.prototype.process = function () {
|
|
1070
|
-
var res = CheckSimple(this.srv.get());
|
|
1071
|
-
if (!res) {
|
|
1072
|
-
ToLogin(this.cog, this.injector, this.url);
|
|
1073
|
-
}
|
|
1074
|
-
return res;
|
|
1075
|
-
};
|
|
1076
|
-
// lazy loading
|
|
1077
|
-
SimpleGuard.prototype.canLoad = function (route, _segments) {
|
|
1078
|
-
this.url = route.path;
|
|
1079
|
-
return this.process();
|
|
1080
|
-
};
|
|
1081
|
-
// all children route
|
|
1082
|
-
SimpleGuard.prototype.canActivateChild = function (_childRoute, state) {
|
|
1083
|
-
this.url = state.url;
|
|
1084
|
-
return this.process();
|
|
1085
|
-
};
|
|
1086
|
-
// route
|
|
1087
|
-
SimpleGuard.prototype.canActivate = function (_route, state) {
|
|
1088
|
-
this.url = state.url;
|
|
1089
|
-
return this.process();
|
|
1090
|
-
};
|
|
1091
|
-
return SimpleGuard;
|
|
1092
|
-
}());
|
|
1093
|
-
SimpleGuard.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function SimpleGuard_Factory() { return new SimpleGuard(i0__namespace.ɵɵinject(DA_SERVICE_TOKEN), i0__namespace.ɵɵinject(i0__namespace.INJECTOR)); }, token: SimpleGuard, providedIn: "root" });
|
|
1094
|
-
SimpleGuard.decorators = [
|
|
1095
|
-
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
1096
|
-
];
|
|
1097
|
-
SimpleGuard.ctorParameters = function () { return [
|
|
1098
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: [DA_SERVICE_TOKEN,] }] },
|
|
1099
|
-
{ type: i0.Injector }
|
|
1100
|
-
]; };
|
|
1101
|
-
|
|
1102
|
-
var DelonAuthModule = /** @class */ (function () {
|
|
1103
|
-
function DelonAuthModule() {
|
|
1104
|
-
}
|
|
1105
|
-
return DelonAuthModule;
|
|
1106
|
-
}());
|
|
1107
|
-
DelonAuthModule.decorators = [
|
|
1108
|
-
{ type: i0.NgModule, args: [{},] }
|
|
1109
|
-
];
|
|
1110
|
-
|
|
1111
|
-
/**
|
|
1112
|
-
* Generated bundle index. Do not edit.
|
|
1113
|
-
*/
|
|
1114
|
-
|
|
1115
|
-
exports.AUTH_DEFAULT_CONFIG = AUTH_DEFAULT_CONFIG;
|
|
1116
|
-
exports.BaseInterceptor = BaseInterceptor;
|
|
1117
|
-
exports.CookieStorageStore = CookieStorageStore;
|
|
1118
|
-
exports.DA_SERVICE_TOKEN = DA_SERVICE_TOKEN;
|
|
1119
|
-
exports.DA_SERVICE_TOKEN_FACTORY = DA_SERVICE_TOKEN_FACTORY;
|
|
1120
|
-
exports.DA_STORE_TOKEN = DA_STORE_TOKEN;
|
|
1121
|
-
exports.DA_STORE_TOKEN_LOCAL_FACTORY = DA_STORE_TOKEN_LOCAL_FACTORY;
|
|
1122
|
-
exports.DelonAuthModule = DelonAuthModule;
|
|
1123
|
-
exports.JWTGuard = JWTGuard;
|
|
1124
|
-
exports.JWTInterceptor = JWTInterceptor;
|
|
1125
|
-
exports.JWTTokenModel = JWTTokenModel;
|
|
1126
|
-
exports.LocalStorageStore = LocalStorageStore;
|
|
1127
|
-
exports.MemoryStore = MemoryStore;
|
|
1128
|
-
exports.SessionStorageStore = SessionStorageStore;
|
|
1129
|
-
exports.SimpleGuard = SimpleGuard;
|
|
1130
|
-
exports.SimpleInterceptor = SimpleInterceptor;
|
|
1131
|
-
exports.SimpleTokenModel = SimpleTokenModel;
|
|
1132
|
-
exports.SocialService = SocialService;
|
|
1133
|
-
exports.TokenService = TokenService;
|
|
1134
|
-
exports.mergeConfig = mergeConfig;
|
|
1135
|
-
exports.urlBase64Decode = urlBase64Decode;
|
|
1136
|
-
|
|
1137
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1138
|
-
|
|
1139
|
-
}));
|
|
1140
|
-
//# sourceMappingURL=auth.umd.js.map
|