ngx-oauth 1.1.0 → 2.1.2
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/README.md +39 -10
- package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- package/esm2020/lib/components/login/oauth-login.component.mjs +104 -0
- package/esm2020/lib/models/index.mjs +21 -0
- package/esm2020/lib/oauth.module.mjs +130 -0
- package/esm2020/lib/services/oauth.interceptor.mjs +57 -0
- package/esm2020/lib/services/oauth.service.mjs +398 -0
- package/{esm2015/ngx-oauth.js → esm2020/ngx-oauth.mjs} +0 -0
- package/fesm2015/ngx-oauth.mjs +661 -0
- package/fesm2015/ngx-oauth.mjs.map +1 -0
- package/fesm2020/ngx-oauth.mjs +698 -0
- package/fesm2020/ngx-oauth.mjs.map +1 -0
- package/lib/components/login/oauth-login.component.d.ts +12 -5
- package/lib/models/index.d.ts +41 -3
- package/lib/oauth.module.d.ts +9 -0
- package/lib/services/oauth.interceptor.d.ts +3 -0
- package/lib/services/oauth.service.d.ts +22 -4
- package/ngx-oauth.d.ts +1 -0
- package/package.json +42 -9
- package/bundles/ngx-oauth.umd.js +0 -988
- package/bundles/ngx-oauth.umd.js.map +0 -1
- package/esm2015/lib/components/login/oauth-login.component.js +0 -82
- package/esm2015/lib/models/index.js +0 -20
- package/esm2015/lib/oauth.module.js +0 -112
- package/esm2015/lib/services/oauth.interceptor.js +0 -54
- package/esm2015/lib/services/oauth.service.js +0 -310
- package/fesm2015/ngx-oauth.js +0 -569
- package/fesm2015/ngx-oauth.js.map +0 -1
- package/ngx-oauth.metadata.json +0 -1
package/bundles/ngx-oauth.umd.js
DELETED
|
@@ -1,988 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('rxjs/operators'), require('rxjs'), require('@angular/forms'), require('@angular/router'), require('@angular/common')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('ngx-oauth', ['exports', '@angular/core', '@angular/common/http', 'rxjs/operators', 'rxjs', '@angular/forms', '@angular/router', '@angular/common'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-oauth'] = {}, global.ng.core, global.ng.common.http, global.rxjs.operators, global.rxjs, global.ng.forms, global.ng.router, global.ng.common));
|
|
5
|
-
}(this, (function (exports, core, http, operators, rxjs, forms, router, common) { 'use strict';
|
|
6
|
-
|
|
7
|
-
var SERVER_HOST = new core.InjectionToken('SERVER_HOST');
|
|
8
|
-
var SERVER_PATH = new core.InjectionToken('SERVER_PATH');
|
|
9
|
-
var LOCATION = new core.InjectionToken('Location');
|
|
10
|
-
var STORAGE = new core.InjectionToken('Storage');
|
|
11
|
-
var OAUTH_CONFIG = new core.InjectionToken('OAuthConfig');
|
|
12
|
-
exports.OAuthType = void 0;
|
|
13
|
-
(function (OAuthType) {
|
|
14
|
-
OAuthType["RESOURCE"] = "password";
|
|
15
|
-
OAuthType["AUTHORIZATION_CODE"] = "code";
|
|
16
|
-
OAuthType["IMPLICIT"] = "token";
|
|
17
|
-
OAuthType["CLIENT_CREDENTIAL"] = "client_credentials";
|
|
18
|
-
})(exports.OAuthType || (exports.OAuthType = {}));
|
|
19
|
-
exports.OAuthStatus = void 0;
|
|
20
|
-
(function (OAuthStatus) {
|
|
21
|
-
OAuthStatus["NOT_AUTHORIZED"] = "NOT_AUTHORIZED";
|
|
22
|
-
OAuthStatus["AUTHORIZED"] = "AUTHORIZED";
|
|
23
|
-
OAuthStatus["DENIED"] = "DENIED";
|
|
24
|
-
})(exports.OAuthStatus || (exports.OAuthStatus = {}));
|
|
25
|
-
|
|
26
|
-
/*! *****************************************************************************
|
|
27
|
-
Copyright (c) Microsoft Corporation.
|
|
28
|
-
|
|
29
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
30
|
-
purpose with or without fee is hereby granted.
|
|
31
|
-
|
|
32
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
33
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
34
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
35
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
36
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
37
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
38
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
39
|
-
***************************************************************************** */
|
|
40
|
-
/* global Reflect, Promise */
|
|
41
|
-
var extendStatics = function (d, b) {
|
|
42
|
-
extendStatics = Object.setPrototypeOf ||
|
|
43
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
44
|
-
function (d, b) { for (var p in b)
|
|
45
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
46
|
-
d[p] = b[p]; };
|
|
47
|
-
return extendStatics(d, b);
|
|
48
|
-
};
|
|
49
|
-
function __extends(d, b) {
|
|
50
|
-
if (typeof b !== "function" && b !== null)
|
|
51
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
52
|
-
extendStatics(d, b);
|
|
53
|
-
function __() { this.constructor = d; }
|
|
54
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
55
|
-
}
|
|
56
|
-
var __assign = function () {
|
|
57
|
-
__assign = Object.assign || function __assign(t) {
|
|
58
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
59
|
-
s = arguments[i];
|
|
60
|
-
for (var p in s)
|
|
61
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
62
|
-
t[p] = s[p];
|
|
63
|
-
}
|
|
64
|
-
return t;
|
|
65
|
-
};
|
|
66
|
-
return __assign.apply(this, arguments);
|
|
67
|
-
};
|
|
68
|
-
function __rest(s, e) {
|
|
69
|
-
var t = {};
|
|
70
|
-
for (var p in s)
|
|
71
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
72
|
-
t[p] = s[p];
|
|
73
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
74
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
75
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
76
|
-
t[p[i]] = s[p[i]];
|
|
77
|
-
}
|
|
78
|
-
return t;
|
|
79
|
-
}
|
|
80
|
-
function __decorate(decorators, target, key, desc) {
|
|
81
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
82
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
83
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
84
|
-
else
|
|
85
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
86
|
-
if (d = decorators[i])
|
|
87
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
88
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
89
|
-
}
|
|
90
|
-
function __param(paramIndex, decorator) {
|
|
91
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
92
|
-
}
|
|
93
|
-
function __metadata(metadataKey, metadataValue) {
|
|
94
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
95
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
96
|
-
}
|
|
97
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
98
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
99
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
100
|
-
function fulfilled(value) { try {
|
|
101
|
-
step(generator.next(value));
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
reject(e);
|
|
105
|
-
} }
|
|
106
|
-
function rejected(value) { try {
|
|
107
|
-
step(generator["throw"](value));
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
reject(e);
|
|
111
|
-
} }
|
|
112
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
113
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function __generator(thisArg, body) {
|
|
117
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
118
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
119
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
120
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
121
|
-
function step(op) {
|
|
122
|
-
if (f)
|
|
123
|
-
throw new TypeError("Generator is already executing.");
|
|
124
|
-
while (_)
|
|
125
|
-
try {
|
|
126
|
-
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)
|
|
127
|
-
return t;
|
|
128
|
-
if (y = 0, t)
|
|
129
|
-
op = [op[0] & 2, t.value];
|
|
130
|
-
switch (op[0]) {
|
|
131
|
-
case 0:
|
|
132
|
-
case 1:
|
|
133
|
-
t = op;
|
|
134
|
-
break;
|
|
135
|
-
case 4:
|
|
136
|
-
_.label++;
|
|
137
|
-
return { value: op[1], done: false };
|
|
138
|
-
case 5:
|
|
139
|
-
_.label++;
|
|
140
|
-
y = op[1];
|
|
141
|
-
op = [0];
|
|
142
|
-
continue;
|
|
143
|
-
case 7:
|
|
144
|
-
op = _.ops.pop();
|
|
145
|
-
_.trys.pop();
|
|
146
|
-
continue;
|
|
147
|
-
default:
|
|
148
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
149
|
-
_ = 0;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
153
|
-
_.label = op[1];
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
157
|
-
_.label = t[1];
|
|
158
|
-
t = op;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
if (t && _.label < t[2]) {
|
|
162
|
-
_.label = t[2];
|
|
163
|
-
_.ops.push(op);
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
if (t[2])
|
|
167
|
-
_.ops.pop();
|
|
168
|
-
_.trys.pop();
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
op = body.call(thisArg, _);
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
op = [6, e];
|
|
175
|
-
y = 0;
|
|
176
|
-
}
|
|
177
|
-
finally {
|
|
178
|
-
f = t = 0;
|
|
179
|
-
}
|
|
180
|
-
if (op[0] & 5)
|
|
181
|
-
throw op[1];
|
|
182
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
186
|
-
if (k2 === undefined)
|
|
187
|
-
k2 = k;
|
|
188
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
189
|
-
}) : (function (o, m, k, k2) {
|
|
190
|
-
if (k2 === undefined)
|
|
191
|
-
k2 = k;
|
|
192
|
-
o[k2] = m[k];
|
|
193
|
-
});
|
|
194
|
-
function __exportStar(m, o) {
|
|
195
|
-
for (var p in m)
|
|
196
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
197
|
-
__createBinding(o, m, p);
|
|
198
|
-
}
|
|
199
|
-
function __values(o) {
|
|
200
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
201
|
-
if (m)
|
|
202
|
-
return m.call(o);
|
|
203
|
-
if (o && typeof o.length === "number")
|
|
204
|
-
return {
|
|
205
|
-
next: function () {
|
|
206
|
-
if (o && i >= o.length)
|
|
207
|
-
o = void 0;
|
|
208
|
-
return { value: o && o[i++], done: !o };
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
212
|
-
}
|
|
213
|
-
function __read(o, n) {
|
|
214
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
215
|
-
if (!m)
|
|
216
|
-
return o;
|
|
217
|
-
var i = m.call(o), r, ar = [], e;
|
|
218
|
-
try {
|
|
219
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
220
|
-
ar.push(r.value);
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
e = { error: error };
|
|
224
|
-
}
|
|
225
|
-
finally {
|
|
226
|
-
try {
|
|
227
|
-
if (r && !r.done && (m = i["return"]))
|
|
228
|
-
m.call(i);
|
|
229
|
-
}
|
|
230
|
-
finally {
|
|
231
|
-
if (e)
|
|
232
|
-
throw e.error;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return ar;
|
|
236
|
-
}
|
|
237
|
-
/** @deprecated */
|
|
238
|
-
function __spread() {
|
|
239
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
240
|
-
ar = ar.concat(__read(arguments[i]));
|
|
241
|
-
return ar;
|
|
242
|
-
}
|
|
243
|
-
/** @deprecated */
|
|
244
|
-
function __spreadArrays() {
|
|
245
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
246
|
-
s += arguments[i].length;
|
|
247
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
248
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
249
|
-
r[k] = a[j];
|
|
250
|
-
return r;
|
|
251
|
-
}
|
|
252
|
-
function __spreadArray(to, from, pack) {
|
|
253
|
-
if (pack || arguments.length === 2)
|
|
254
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
255
|
-
if (ar || !(i in from)) {
|
|
256
|
-
if (!ar)
|
|
257
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
258
|
-
ar[i] = from[i];
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
262
|
-
}
|
|
263
|
-
function __await(v) {
|
|
264
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
265
|
-
}
|
|
266
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
267
|
-
if (!Symbol.asyncIterator)
|
|
268
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
269
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
270
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
271
|
-
function verb(n) { if (g[n])
|
|
272
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
273
|
-
function resume(n, v) { try {
|
|
274
|
-
step(g[n](v));
|
|
275
|
-
}
|
|
276
|
-
catch (e) {
|
|
277
|
-
settle(q[0][3], e);
|
|
278
|
-
} }
|
|
279
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
280
|
-
function fulfill(value) { resume("next", value); }
|
|
281
|
-
function reject(value) { resume("throw", value); }
|
|
282
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
283
|
-
resume(q[0][0], q[0][1]); }
|
|
284
|
-
}
|
|
285
|
-
function __asyncDelegator(o) {
|
|
286
|
-
var i, p;
|
|
287
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
288
|
-
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; }
|
|
289
|
-
}
|
|
290
|
-
function __asyncValues(o) {
|
|
291
|
-
if (!Symbol.asyncIterator)
|
|
292
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
293
|
-
var m = o[Symbol.asyncIterator], i;
|
|
294
|
-
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);
|
|
295
|
-
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); }); }; }
|
|
296
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
297
|
-
}
|
|
298
|
-
function __makeTemplateObject(cooked, raw) {
|
|
299
|
-
if (Object.defineProperty) {
|
|
300
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
cooked.raw = raw;
|
|
304
|
-
}
|
|
305
|
-
return cooked;
|
|
306
|
-
}
|
|
307
|
-
;
|
|
308
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
309
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
310
|
-
}) : function (o, v) {
|
|
311
|
-
o["default"] = v;
|
|
312
|
-
};
|
|
313
|
-
function __importStar(mod) {
|
|
314
|
-
if (mod && mod.__esModule)
|
|
315
|
-
return mod;
|
|
316
|
-
var result = {};
|
|
317
|
-
if (mod != null)
|
|
318
|
-
for (var k in mod)
|
|
319
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
320
|
-
__createBinding(result, mod, k);
|
|
321
|
-
__setModuleDefault(result, mod);
|
|
322
|
-
return result;
|
|
323
|
-
}
|
|
324
|
-
function __importDefault(mod) {
|
|
325
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
326
|
-
}
|
|
327
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
328
|
-
if (kind === "a" && !f)
|
|
329
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
330
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
331
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
332
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
333
|
-
}
|
|
334
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
335
|
-
if (kind === "m")
|
|
336
|
-
throw new TypeError("Private method is not writable");
|
|
337
|
-
if (kind === "a" && !f)
|
|
338
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
339
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
340
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
341
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
var base64url = function (str) { return btoa(str)
|
|
345
|
-
.replace(/\+/g, '-')
|
|
346
|
-
.replace(/\//g, '_')
|
|
347
|
-
.replace(/=/g, ''); };
|
|
348
|
-
var ɵ0$1 = base64url;
|
|
349
|
-
var pkce = function (value) { return __awaiter(void 0, void 0, void 0, function () {
|
|
350
|
-
var buff;
|
|
351
|
-
return __generator(this, function (_b) {
|
|
352
|
-
switch (_b.label) {
|
|
353
|
-
case 0: return [4 /*yield*/, crypto.subtle.digest('SHA-256', new TextEncoder().encode(value))];
|
|
354
|
-
case 1:
|
|
355
|
-
buff = _b.sent();
|
|
356
|
-
return [2 /*return*/, base64url(new Uint8Array(buff).reduce(function (s, b) { return s + String.fromCharCode(b); }, ''))];
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
}); };
|
|
360
|
-
var ɵ1$1 = pkce;
|
|
361
|
-
var REQUEST_HEADER = new http.HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });
|
|
362
|
-
var parseOauthUri = function (hash) {
|
|
363
|
-
var regex = /([^&=]+)=([^&]*)/g;
|
|
364
|
-
var params = {};
|
|
365
|
-
var m;
|
|
366
|
-
// tslint:disable-next-line:no-conditional-assignment
|
|
367
|
-
while ((m = regex.exec(hash)) !== null) {
|
|
368
|
-
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
|
|
369
|
-
}
|
|
370
|
-
if (Object.keys(params).length) {
|
|
371
|
-
return params;
|
|
372
|
-
}
|
|
373
|
-
return null;
|
|
374
|
-
};
|
|
375
|
-
var ɵ2 = parseOauthUri;
|
|
376
|
-
var OAuthService = /** @class */ (function () {
|
|
377
|
-
function OAuthService(http, zone, authConfig, locationService) {
|
|
378
|
-
this.http = http;
|
|
379
|
-
this.zone = zone;
|
|
380
|
-
this.authConfig = authConfig;
|
|
381
|
-
this.locationService = locationService;
|
|
382
|
-
this._token = null;
|
|
383
|
-
this._status = exports.OAuthStatus.NOT_AUTHORIZED;
|
|
384
|
-
this.state$ = new rxjs.ReplaySubject(1);
|
|
385
|
-
this.status$ = new rxjs.ReplaySubject(1);
|
|
386
|
-
this.init();
|
|
387
|
-
}
|
|
388
|
-
OAuthService.prototype.init = function () {
|
|
389
|
-
var _this = this;
|
|
390
|
-
var _b = this.locationService, hash = _b.hash, search = _b.search, origin = _b.origin, pathname = _b.pathname;
|
|
391
|
-
var isImplicitRedirect = hash && new RegExp('(#access_token=)|(#error=)').test(hash);
|
|
392
|
-
var isAuthCodeRedirect = search && new RegExp('(code=)|(error=)').test(search);
|
|
393
|
-
var storageKey = this.authConfig.storageKey;
|
|
394
|
-
var savedToken = storageKey && this.authConfig.storage && this.authConfig.storage[storageKey] &&
|
|
395
|
-
JSON.parse(this.authConfig.storage[storageKey]);
|
|
396
|
-
if (isImplicitRedirect) {
|
|
397
|
-
var parameters = parseOauthUri(hash.substr(1));
|
|
398
|
-
this.emitState(parameters);
|
|
399
|
-
this.cleanLocationHash();
|
|
400
|
-
if (!parameters || parameters.error) {
|
|
401
|
-
this.token = null;
|
|
402
|
-
this.status = exports.OAuthStatus.DENIED;
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
this.token = parameters;
|
|
406
|
-
this.status = exports.OAuthStatus.AUTHORIZED;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
else if (isAuthCodeRedirect) {
|
|
410
|
-
var parameters_1 = parseOauthUri(search.substr(1));
|
|
411
|
-
this.emitState(parameters_1);
|
|
412
|
-
var newParametersString_1 = this.getCleanedUnSearchParameters();
|
|
413
|
-
if (parameters_1 && parameters_1.code) {
|
|
414
|
-
var _c = this.authConfig.config, clientId_1 = _c.clientId, clientSecret_1 = _c.clientSecret, tokenPath_1 = _c.tokenPath, scope_1 = _c.scope, codeVerifier_1 = _c.codeVerifier;
|
|
415
|
-
setTimeout(function () {
|
|
416
|
-
_this.http.post(tokenPath_1, new http.HttpParams({
|
|
417
|
-
fromObject: Object.assign(Object.assign({ code: parameters_1.code, client_id: clientId_1, client_secret: clientSecret_1, redirect_uri: "" + origin + pathname + newParametersString_1, grant_type: 'authorization_code' }, scope_1 ? { scope: scope_1 } : {}), codeVerifier_1 ? { code_verifier: codeVerifier_1 } : {})
|
|
418
|
-
}), { headers: REQUEST_HEADER }).pipe(operators.catchError(function () {
|
|
419
|
-
_this.token = { error: 'error' };
|
|
420
|
-
_this.status = exports.OAuthStatus.DENIED;
|
|
421
|
-
_this.locationService.href = "" + origin + pathname + newParametersString_1;
|
|
422
|
-
return rxjs.EMPTY;
|
|
423
|
-
})).subscribe(function (token) {
|
|
424
|
-
_this.token = token;
|
|
425
|
-
// authorized event will be triggered after redirect
|
|
426
|
-
_this.locationService.href = "" + origin + pathname + newParametersString_1;
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
this.token = null;
|
|
432
|
-
this.status = exports.OAuthStatus.DENIED;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
else if (savedToken) {
|
|
436
|
-
var access_token = savedToken.access_token, refresh_token = savedToken.refresh_token, error = savedToken.error;
|
|
437
|
-
if (error) {
|
|
438
|
-
this.token = null;
|
|
439
|
-
this.status = exports.OAuthStatus.DENIED;
|
|
440
|
-
}
|
|
441
|
-
else if (access_token) {
|
|
442
|
-
this.token = savedToken;
|
|
443
|
-
if (refresh_token) {
|
|
444
|
-
setTimeout(function () {
|
|
445
|
-
_this.refreshToken();
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
this.status = exports.OAuthStatus.AUTHORIZED;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
this.status = exports.OAuthStatus.NOT_AUTHORIZED;
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
OAuthService.prototype.login = function (parameters) {
|
|
458
|
-
if (this.isResourceType(parameters)) {
|
|
459
|
-
this.resourceLogin(parameters);
|
|
460
|
-
}
|
|
461
|
-
else if (this.isAuthorizationCodeType(parameters)) {
|
|
462
|
-
this.authorizationCodeLogin(parameters).then();
|
|
463
|
-
}
|
|
464
|
-
else if (this.isImplicitType(parameters)) {
|
|
465
|
-
this.implicitLogin(parameters).then();
|
|
466
|
-
}
|
|
467
|
-
else if (this.isClientCredentialType()) {
|
|
468
|
-
this.clientCredentialLogin();
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
OAuthService.prototype.logout = function () {
|
|
472
|
-
this.revoke();
|
|
473
|
-
this.token = null;
|
|
474
|
-
this.status = exports.OAuthStatus.NOT_AUTHORIZED;
|
|
475
|
-
};
|
|
476
|
-
OAuthService.prototype.revoke = function () {
|
|
477
|
-
var _this = this;
|
|
478
|
-
var _b = this.authConfig.config, revokePath = _b.revokePath, clientId = _b.clientId, clientSecret = _b.clientSecret;
|
|
479
|
-
if (revokePath) {
|
|
480
|
-
var _c = this.token, access_token = _c.access_token, refresh_token = _c.refresh_token;
|
|
481
|
-
var toRevoke = [];
|
|
482
|
-
if (access_token) {
|
|
483
|
-
toRevoke.push(Object.assign(Object.assign(Object.assign({}, clientId ? { client_id: clientId } : {}), clientSecret ? { client_secret: clientSecret } : {}), { token: access_token, token_type_hint: 'access_token' }));
|
|
484
|
-
}
|
|
485
|
-
if (refresh_token) {
|
|
486
|
-
toRevoke.push(Object.assign(Object.assign(Object.assign({}, clientId ? { client_id: clientId } : {}), clientSecret ? { client_secret: clientSecret } : {}), { token: refresh_token, token_type_hint: 'refresh_token' }));
|
|
487
|
-
}
|
|
488
|
-
rxjs.from(toRevoke).pipe(operators.concatMap(function (o) { return rxjs.of(o).pipe(operators.delay(300)); }), // space request to avoid cancellation
|
|
489
|
-
operators.switchMap(function (o) { return _this.http.post(revokePath, new http.HttpParams({ fromObject: o })); })).subscribe(rxjs.noop);
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
Object.defineProperty(OAuthService.prototype, "status", {
|
|
493
|
-
get: function () {
|
|
494
|
-
return this._status;
|
|
495
|
-
},
|
|
496
|
-
set: function (status) {
|
|
497
|
-
this._status = status;
|
|
498
|
-
this.status$.next(status);
|
|
499
|
-
},
|
|
500
|
-
enumerable: false,
|
|
501
|
-
configurable: true
|
|
502
|
-
});
|
|
503
|
-
OAuthService.prototype.set = function (type, config) {
|
|
504
|
-
this.authConfig.type = type;
|
|
505
|
-
if (config) {
|
|
506
|
-
this.authConfig.config = Object.assign(Object.assign({}, this.authConfig.config), config);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
Object.defineProperty(OAuthService.prototype, "type", {
|
|
510
|
-
get: function () {
|
|
511
|
-
return this.authConfig.type;
|
|
512
|
-
},
|
|
513
|
-
enumerable: false,
|
|
514
|
-
configurable: true
|
|
515
|
-
});
|
|
516
|
-
Object.defineProperty(OAuthService.prototype, "ignorePaths", {
|
|
517
|
-
get: function () {
|
|
518
|
-
return this.authConfig.ignorePaths || [];
|
|
519
|
-
},
|
|
520
|
-
enumerable: false,
|
|
521
|
-
configurable: true
|
|
522
|
-
});
|
|
523
|
-
OAuthService.prototype.resourceLogin = function (parameters) {
|
|
524
|
-
var _this = this;
|
|
525
|
-
var _b = this.authConfig.config, clientId = _b.clientId, clientSecret = _b.clientSecret, tokenPath = _b.tokenPath, scope = _b.scope;
|
|
526
|
-
var username = parameters.username, password = parameters.password;
|
|
527
|
-
this.http.post(tokenPath, new http.HttpParams({
|
|
528
|
-
fromObject: Object.assign(Object.assign({ client_id: clientId, client_secret: clientSecret, grant_type: exports.OAuthType.RESOURCE }, scope ? { scope: scope } : {}), { username: username, password: password })
|
|
529
|
-
}), { headers: REQUEST_HEADER }).pipe(operators.catchError(function () {
|
|
530
|
-
_this.token = null;
|
|
531
|
-
_this.status = exports.OAuthStatus.DENIED;
|
|
532
|
-
return rxjs.EMPTY;
|
|
533
|
-
})).subscribe(function (params) {
|
|
534
|
-
_this.token = params;
|
|
535
|
-
_this.status = exports.OAuthStatus.AUTHORIZED;
|
|
536
|
-
});
|
|
537
|
-
};
|
|
538
|
-
OAuthService.prototype.authorizationCodeLogin = function (parameters) {
|
|
539
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
540
|
-
var authUrl;
|
|
541
|
-
return __generator(this, function (_b) {
|
|
542
|
-
switch (_b.label) {
|
|
543
|
-
case 0: return [4 /*yield*/, this.toAuthorizationUrl(parameters, exports.OAuthType.AUTHORIZATION_CODE)];
|
|
544
|
-
case 1:
|
|
545
|
-
authUrl = _b.sent();
|
|
546
|
-
this.locationService.replace(authUrl);
|
|
547
|
-
return [2 /*return*/];
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
};
|
|
552
|
-
OAuthService.prototype.implicitLogin = function (parameters) {
|
|
553
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
554
|
-
var authUrl;
|
|
555
|
-
return __generator(this, function (_b) {
|
|
556
|
-
switch (_b.label) {
|
|
557
|
-
case 0: return [4 /*yield*/, this.toAuthorizationUrl(parameters, exports.OAuthType.IMPLICIT)];
|
|
558
|
-
case 1:
|
|
559
|
-
authUrl = _b.sent();
|
|
560
|
-
this.locationService.replace(authUrl);
|
|
561
|
-
return [2 /*return*/];
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
};
|
|
566
|
-
OAuthService.prototype.clientCredentialLogin = function () {
|
|
567
|
-
var _this = this;
|
|
568
|
-
var _b = this.authConfig.config, clientId = _b.clientId, clientSecret = _b.clientSecret, tokenPath = _b.tokenPath, scope = _b.scope;
|
|
569
|
-
this.http.post(tokenPath, new http.HttpParams({
|
|
570
|
-
fromObject: Object.assign({ client_id: clientId, client_secret: clientSecret, grant_type: exports.OAuthType.CLIENT_CREDENTIAL }, scope ? { scope: scope } : {})
|
|
571
|
-
}), { headers: REQUEST_HEADER }).pipe(operators.catchError(function () {
|
|
572
|
-
_this.token = null;
|
|
573
|
-
_this.status = exports.OAuthStatus.DENIED;
|
|
574
|
-
return rxjs.EMPTY;
|
|
575
|
-
})).subscribe(function (params) {
|
|
576
|
-
_this.token = params;
|
|
577
|
-
_this.status = exports.OAuthStatus.AUTHORIZED;
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
OAuthService.prototype.isClientCredentialType = function () {
|
|
581
|
-
return this.authConfig.type === exports.OAuthType.CLIENT_CREDENTIAL;
|
|
582
|
-
};
|
|
583
|
-
OAuthService.prototype.isResourceType = function (parameters) {
|
|
584
|
-
return this.authConfig.type === exports.OAuthType.RESOURCE && !!(parameters === null || parameters === void 0 ? void 0 : parameters.password);
|
|
585
|
-
};
|
|
586
|
-
OAuthService.prototype.isImplicitType = function (parameters) {
|
|
587
|
-
return this.authConfig.type === exports.OAuthType.IMPLICIT && !!(parameters === null || parameters === void 0 ? void 0 : parameters.redirectUri);
|
|
588
|
-
};
|
|
589
|
-
OAuthService.prototype.isAuthorizationCodeType = function (parameters) {
|
|
590
|
-
return this.authConfig.type === exports.OAuthType.AUTHORIZATION_CODE && !!(parameters === null || parameters === void 0 ? void 0 : parameters.redirectUri);
|
|
591
|
-
};
|
|
592
|
-
OAuthService.prototype.toAuthorizationUrl = function (parameters, responseType) {
|
|
593
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
594
|
-
var config, appendChar, clientId, redirectUri, responseTypeString, scope, state, codeVerifier, codeChallenge, _b, _c, parametersString;
|
|
595
|
-
return __generator(this, function (_d) {
|
|
596
|
-
switch (_d.label) {
|
|
597
|
-
case 0:
|
|
598
|
-
config = this.authConfig.config;
|
|
599
|
-
appendChar = config.authorizePath.includes('?') ? '&' : '?';
|
|
600
|
-
clientId = appendChar + "client_id=" + config.clientId;
|
|
601
|
-
redirectUri = "&redirect_uri=" + encodeURIComponent(parameters.redirectUri);
|
|
602
|
-
responseTypeString = "&response_type=" + responseType;
|
|
603
|
-
scope = "&scope=" + encodeURIComponent(config.scope || '');
|
|
604
|
-
state = "&state=" + encodeURIComponent(parameters.state || '');
|
|
605
|
-
codeVerifier = config.codeVerifier;
|
|
606
|
-
if (!codeVerifier) return [3 /*break*/, 2];
|
|
607
|
-
_c = "&code_challenge=";
|
|
608
|
-
return [4 /*yield*/, pkce(codeVerifier)];
|
|
609
|
-
case 1:
|
|
610
|
-
_b = _c + (_d.sent()) + "&code_challenge_method=S256";
|
|
611
|
-
return [3 /*break*/, 3];
|
|
612
|
-
case 2:
|
|
613
|
-
_b = '';
|
|
614
|
-
_d.label = 3;
|
|
615
|
-
case 3:
|
|
616
|
-
codeChallenge = _b;
|
|
617
|
-
parametersString = "" + clientId + redirectUri + responseTypeString + scope + state + codeChallenge;
|
|
618
|
-
return [2 /*return*/, "" + config.authorizePath + parametersString];
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
};
|
|
623
|
-
Object.defineProperty(OAuthService.prototype, "token", {
|
|
624
|
-
get: function () {
|
|
625
|
-
return this._token;
|
|
626
|
-
},
|
|
627
|
-
set: function (token) {
|
|
628
|
-
var _this = this;
|
|
629
|
-
this._token = token;
|
|
630
|
-
var storageKey = this.authConfig.storageKey;
|
|
631
|
-
if (token) {
|
|
632
|
-
// @ts-ignore
|
|
633
|
-
this.authConfig.storage[storageKey] = JSON.stringify(this.token);
|
|
634
|
-
clearTimeout(this.timer);
|
|
635
|
-
if (this.token && this.token.expires_in) {
|
|
636
|
-
this.zone.runOutsideAngular(function () {
|
|
637
|
-
var _a;
|
|
638
|
-
_this.timer = setTimeout(function () {
|
|
639
|
-
_this.zone.run(function () {
|
|
640
|
-
_this.refreshToken();
|
|
641
|
-
});
|
|
642
|
-
}, Number((_a = _this.token) === null || _a === void 0 ? void 0 : _a.expires_in) * 1000);
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
// @ts-ignore
|
|
648
|
-
delete this.authConfig.storage[storageKey];
|
|
649
|
-
}
|
|
650
|
-
},
|
|
651
|
-
enumerable: false,
|
|
652
|
-
configurable: true
|
|
653
|
-
});
|
|
654
|
-
OAuthService.prototype.refreshToken = function () {
|
|
655
|
-
var _this = this;
|
|
656
|
-
var _b = this.authConfig.config, tokenPath = _b.tokenPath, clientId = _b.clientId, clientSecret = _b.clientSecret, scope = _b.scope;
|
|
657
|
-
var refresh_token = this.token.refresh_token;
|
|
658
|
-
if (tokenPath && refresh_token) {
|
|
659
|
-
this.http.post(tokenPath, new http.HttpParams({
|
|
660
|
-
fromObject: Object.assign({ client_id: clientId, client_secret: clientSecret, grant_type: 'refresh_token', refresh_token: refresh_token }, scope ? { scope: scope } : {})
|
|
661
|
-
}), { headers: REQUEST_HEADER }).pipe(operators.catchError(function () {
|
|
662
|
-
_this.logout();
|
|
663
|
-
return rxjs.EMPTY;
|
|
664
|
-
})).subscribe(function (params) {
|
|
665
|
-
_this.token = Object.assign(Object.assign({}, _this.token), params);
|
|
666
|
-
_this.status = exports.OAuthStatus.AUTHORIZED;
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
|
-
OAuthService.prototype.getCleanedUnSearchParameters = function () {
|
|
671
|
-
var search = this.locationService.search;
|
|
672
|
-
var searchString = search.substr(1);
|
|
673
|
-
var hashKeys = ['code', 'state', 'error', 'error_description', 'session_state'];
|
|
674
|
-
hashKeys.forEach(function (hashKey) {
|
|
675
|
-
var re = new RegExp('&' + hashKey + '(=[^&]*)?|^' + hashKey + '(=[^&]*)?&?');
|
|
676
|
-
searchString = searchString.replace(re, '');
|
|
677
|
-
});
|
|
678
|
-
return searchString.length ? "?" + searchString : '';
|
|
679
|
-
};
|
|
680
|
-
OAuthService.prototype.cleanLocationHash = function () {
|
|
681
|
-
var hash = this.locationService.hash;
|
|
682
|
-
var curHash = hash.substr(1);
|
|
683
|
-
var hashKeys = ['access_token', 'token_type', 'expires_in', 'scope', 'state', 'error', 'error_description', 'session_state'];
|
|
684
|
-
hashKeys.forEach(function (hashKey) {
|
|
685
|
-
var re = new RegExp('&' + hashKey + '(=[^&]*)?|^' + hashKey + '(=[^&]*)?&?');
|
|
686
|
-
curHash = curHash.replace(re, '');
|
|
687
|
-
});
|
|
688
|
-
this.locationService.hash = curHash;
|
|
689
|
-
};
|
|
690
|
-
OAuthService.prototype.emitState = function (parameters) {
|
|
691
|
-
var state = parameters.state;
|
|
692
|
-
if (state) {
|
|
693
|
-
this.state$.next(state);
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
return OAuthService;
|
|
697
|
-
}());
|
|
698
|
-
OAuthService.decorators = [
|
|
699
|
-
{ type: core.Injectable }
|
|
700
|
-
];
|
|
701
|
-
OAuthService.ctorParameters = function () { return [
|
|
702
|
-
{ type: http.HttpClient },
|
|
703
|
-
{ type: core.NgZone },
|
|
704
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [OAUTH_CONFIG,] }] },
|
|
705
|
-
{ type: Location, decorators: [{ type: core.Inject, args: [LOCATION,] }] }
|
|
706
|
-
]; };
|
|
707
|
-
|
|
708
|
-
var OAuthInterceptor = /** @class */ (function () {
|
|
709
|
-
function OAuthInterceptor(oauthService) {
|
|
710
|
-
this.oauthService = oauthService;
|
|
711
|
-
}
|
|
712
|
-
OAuthInterceptor.prototype.intercept = function (req, next) {
|
|
713
|
-
var _this = this;
|
|
714
|
-
if (this.oauthService) {
|
|
715
|
-
if (!this.isPathExcepted(req)) {
|
|
716
|
-
var token = this.oauthService.token;
|
|
717
|
-
if (token && token.access_token) {
|
|
718
|
-
req = req.clone({
|
|
719
|
-
setHeaders: {
|
|
720
|
-
Authorization: token.token_type + " " + token.access_token
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
return next.handle(req).pipe(operators.catchError(function (err) {
|
|
726
|
-
if (err.status === 401) {
|
|
727
|
-
_this.oauthService.token = null;
|
|
728
|
-
_this.oauthService.status = exports.OAuthStatus.DENIED;
|
|
729
|
-
return rxjs.EMPTY;
|
|
730
|
-
}
|
|
731
|
-
return rxjs.throwError(function () { return new Error(err); });
|
|
732
|
-
}));
|
|
733
|
-
}
|
|
734
|
-
else {
|
|
735
|
-
return next.handle(req);
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
OAuthInterceptor.prototype.isPathExcepted = function (req) {
|
|
739
|
-
var e_1, _a;
|
|
740
|
-
try {
|
|
741
|
-
for (var _b = __values(this.oauthService.ignorePaths), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
742
|
-
var ignorePath = _c.value;
|
|
743
|
-
try {
|
|
744
|
-
if (req.url.match(ignorePath)) {
|
|
745
|
-
return true;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
catch (err) {
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
753
|
-
finally {
|
|
754
|
-
try {
|
|
755
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
756
|
-
}
|
|
757
|
-
finally { if (e_1) throw e_1.error; }
|
|
758
|
-
}
|
|
759
|
-
return false;
|
|
760
|
-
};
|
|
761
|
-
return OAuthInterceptor;
|
|
762
|
-
}());
|
|
763
|
-
OAuthInterceptor.decorators = [
|
|
764
|
-
{ type: core.Injectable }
|
|
765
|
-
];
|
|
766
|
-
OAuthInterceptor.ctorParameters = function () { return [
|
|
767
|
-
{ type: OAuthService }
|
|
768
|
-
]; };
|
|
769
|
-
|
|
770
|
-
var OAuthLoginComponent = /** @class */ (function () {
|
|
771
|
-
function OAuthLoginComponent(oauthService, location) {
|
|
772
|
-
var _this = this;
|
|
773
|
-
this.oauthService = oauthService;
|
|
774
|
-
this.location = location;
|
|
775
|
-
this.subscription = new rxjs.Subscription();
|
|
776
|
-
this._i18n = {
|
|
777
|
-
username: 'Username',
|
|
778
|
-
password: 'Password',
|
|
779
|
-
submit: 'Sign in',
|
|
780
|
-
notAuthorized: 'Sign in',
|
|
781
|
-
authorized: 'Welcome',
|
|
782
|
-
denied: 'Access Denied. Try again!'
|
|
783
|
-
};
|
|
784
|
-
this.state = '';
|
|
785
|
-
this.stateChange = new core.EventEmitter();
|
|
786
|
-
this.username = '';
|
|
787
|
-
this.password = '';
|
|
788
|
-
this.OAuthStatus = exports.OAuthStatus;
|
|
789
|
-
this.OAuthType = exports.OAuthType;
|
|
790
|
-
this.collapse = false;
|
|
791
|
-
this.type = this.oauthService.type;
|
|
792
|
-
this.redirectUri = this.location.href;
|
|
793
|
-
this.state$ = this.oauthService.state$.pipe(operators.tap(function (s) { return _this.stateChange.emit(s); }));
|
|
794
|
-
this.status$ = this.oauthService.status$.pipe(operators.tap(function (s) {
|
|
795
|
-
if (s === exports.OAuthStatus.AUTHORIZED && _this.profileName$) {
|
|
796
|
-
_this.subscription.add(_this.profileName$.subscribe(function (n) { return _this.profileName = n; }));
|
|
797
|
-
}
|
|
798
|
-
else {
|
|
799
|
-
_this.profileName = '';
|
|
800
|
-
}
|
|
801
|
-
}));
|
|
802
|
-
this.loginFunction = function (p) { return _this.login(p); };
|
|
803
|
-
this.logoutFunction = function () { return _this.logout(); };
|
|
804
|
-
}
|
|
805
|
-
Object.defineProperty(OAuthLoginComponent.prototype, "i18n", {
|
|
806
|
-
get: function () {
|
|
807
|
-
return this._i18n;
|
|
808
|
-
},
|
|
809
|
-
set: function (i18n) {
|
|
810
|
-
this._i18n = Object.assign(Object.assign({}, this._i18n), i18n);
|
|
811
|
-
},
|
|
812
|
-
enumerable: false,
|
|
813
|
-
configurable: true
|
|
814
|
-
});
|
|
815
|
-
OAuthLoginComponent.prototype.ngOnDestroy = function () {
|
|
816
|
-
this.subscription.unsubscribe();
|
|
817
|
-
};
|
|
818
|
-
OAuthLoginComponent.prototype.logout = function () {
|
|
819
|
-
this.oauthService.logout();
|
|
820
|
-
};
|
|
821
|
-
OAuthLoginComponent.prototype.login = function (parameters) {
|
|
822
|
-
this.oauthService.login(parameters);
|
|
823
|
-
this.collapse = false;
|
|
824
|
-
};
|
|
825
|
-
OAuthLoginComponent.prototype.toggleCollapse = function () {
|
|
826
|
-
this.collapse = !this.collapse;
|
|
827
|
-
};
|
|
828
|
-
OAuthLoginComponent.prototype.keyboardEvent = function () {
|
|
829
|
-
this.collapse = false;
|
|
830
|
-
};
|
|
831
|
-
return OAuthLoginComponent;
|
|
832
|
-
}());
|
|
833
|
-
OAuthLoginComponent.decorators = [
|
|
834
|
-
{ type: core.Component, args: [{
|
|
835
|
-
selector: 'oauth-login',
|
|
836
|
-
template: "<ng-container *ngIf=\"state$ | async\"></ng-container>\r\n<ng-container *ngIf=\"loginTemplate; else defaultLogin\"\r\n [ngTemplateOutlet]=\"loginTemplate\"\r\n [ngTemplateOutletContext]=\"{login: loginFunction, logout: logoutFunction, status: status$ | async}\">\r\n</ng-container>\r\n<ng-template #defaultLogin>\r\n <ng-container *ngIf=\"status$ | async as status\">\r\n <ng-container *ngIf=\"type === OAuthType.RESOURCE; else noResource\">\r\n <div class=\"oauth dropdown text-right p-3 {{collapse ? 'show': ''}}\">\r\n <button class=\"btn btn-link p-0 dropdown-toggle\"\r\n (click)=\"status === OAuthStatus.AUTHORIZED ? logout() : toggleCollapse()\">\r\n <ng-container *ngTemplateOutlet=\"message\"></ng-container>\r\n </button>\r\n <div class=\"dropdown-menu mr-3 {{collapse ? 'show': ''}}\">\r\n <form class=\"p-3\" #form=\"ngForm\"\r\n *ngIf=\"status === OAuthStatus.NOT_AUTHORIZED || status === OAuthStatus.DENIED\"\r\n (submit)=\"login({username: username, password: password})\">\r\n <div class=\"form-group\">\r\n <input type=\"text\"\r\n class=\"form-control\"\r\n name=\"username\"\r\n required\r\n [(ngModel)]=\"username\"\r\n [placeholder]=\"i18n.username\">\r\n </div>\r\n <div class=\"form-group\">\r\n <input type=\"password\"\r\n class=\"form-control\"\r\n name=\"password\"\r\n required\r\n [(ngModel)]=\"password\"\r\n [placeholder]=\"i18n.password\">\r\n </div>\r\n <div class=\"text-right\">\r\n <button type=\"submit\"\r\n class=\"btn btn-primary\"\r\n [disabled]=\"form.invalid\">{{i18n.submit}}</button>\r\n </div>\r\n </form>\r\n </div>\r\n </div>\r\n </ng-container>\r\n\r\n <ng-template #noResource>\r\n <a role=\"button\" class=\"oauth\"\r\n (click)=\"status === OAuthStatus.AUTHORIZED ? logout() : login({redirectUri: redirectUri, state:state})\">\r\n <ng-container *ngTemplateOutlet=\"message\"></ng-container>\r\n </a>\r\n </ng-template>\r\n\r\n <ng-template #message>\r\n <span *ngIf=\"status === OAuthStatus.NOT_AUTHORIZED\">{{i18n.notAuthorized}}</span>\r\n <span *ngIf=\"status === OAuthStatus.AUTHORIZED\">\r\n {{i18n.authorized}}<strong> {{profileName}}</strong>\r\n </span>\r\n <span *ngIf=\"status === OAuthStatus.DENIED\">{{i18n.denied}}</span>\r\n </ng-template>\r\n </ng-container>\r\n</ng-template>\r\n\r\n",
|
|
837
|
-
styles: [".oauth .dropdown-menu{left:auto;right:0;box-shadow:0 5px 10px #0003;min-width:250px}.oauth .dropdown-menu:before{content:\"\";display:inline-block;border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-bottom-color:#0003;position:absolute;top:-7px;left:auto;right:15px}.oauth .dropdown-menu:after{content:\"\";display:inline-block;border-left:6px solid transparent;border-right:6px solid transparent;border-bottom:6px solid #ffffff;position:absolute;top:-6px;left:auto;right:16px}\n"]
|
|
838
|
-
},] }
|
|
839
|
-
];
|
|
840
|
-
OAuthLoginComponent.ctorParameters = function () { return [
|
|
841
|
-
{ type: OAuthService },
|
|
842
|
-
{ type: Location, decorators: [{ type: core.Inject, args: [LOCATION,] }] }
|
|
843
|
-
]; };
|
|
844
|
-
OAuthLoginComponent.propDecorators = {
|
|
845
|
-
i18n: [{ type: core.Input }],
|
|
846
|
-
state: [{ type: core.Input }],
|
|
847
|
-
stateChange: [{ type: core.Output }],
|
|
848
|
-
profileName$: [{ type: core.Input }],
|
|
849
|
-
loginTemplate: [{ type: core.ContentChild, args: ['login', { static: false },] }],
|
|
850
|
-
keyboardEvent: [{ type: core.HostListener, args: ['window:keydown.escape',] }]
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
var mockLocation = function (serverHost, serverPath) {
|
|
854
|
-
var url = new URL(serverHost && serverPath ? "" + serverHost + serverPath : 'http://localhost');
|
|
855
|
-
var href = url.href, origin = url.origin, protocol = url.protocol, host = url.host, hostname = url.hostname, port = url.port, pathname = url.pathname, search = url.search, hash = url.hash;
|
|
856
|
-
return {
|
|
857
|
-
href: href,
|
|
858
|
-
origin: origin,
|
|
859
|
-
protocol: protocol,
|
|
860
|
-
host: host,
|
|
861
|
-
hostname: hostname,
|
|
862
|
-
port: port,
|
|
863
|
-
pathname: pathname,
|
|
864
|
-
search: search,
|
|
865
|
-
hash: hash,
|
|
866
|
-
reload: function () {
|
|
867
|
-
},
|
|
868
|
-
assign: function (u) {
|
|
869
|
-
},
|
|
870
|
-
ancestorOrigins: {},
|
|
871
|
-
replace: function (u) {
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
var ɵ0 = mockLocation;
|
|
876
|
-
var LocationService = {
|
|
877
|
-
provide: LOCATION,
|
|
878
|
-
useFactory: function (platformId, serverHost, serverPath) {
|
|
879
|
-
return common.isPlatformBrowser(platformId) ? location : mockLocation(serverHost, serverPath);
|
|
880
|
-
},
|
|
881
|
-
deps: [
|
|
882
|
-
core.PLATFORM_ID,
|
|
883
|
-
[new core.Optional(), SERVER_HOST],
|
|
884
|
-
[new core.Optional(), SERVER_PATH]
|
|
885
|
-
]
|
|
886
|
-
};
|
|
887
|
-
var mockStorage = {
|
|
888
|
-
clear: function () {
|
|
889
|
-
},
|
|
890
|
-
getItem: function (key) {
|
|
891
|
-
return null;
|
|
892
|
-
},
|
|
893
|
-
key: function (index) {
|
|
894
|
-
return null;
|
|
895
|
-
},
|
|
896
|
-
removeItem: function (key) {
|
|
897
|
-
},
|
|
898
|
-
setItem: function (key, value) {
|
|
899
|
-
},
|
|
900
|
-
length: 0
|
|
901
|
-
};
|
|
902
|
-
var StorageService = {
|
|
903
|
-
provide: STORAGE,
|
|
904
|
-
useFactory: function (platformId) {
|
|
905
|
-
return common.isPlatformBrowser(platformId) ? localStorage : mockStorage;
|
|
906
|
-
},
|
|
907
|
-
deps: [core.PLATFORM_ID]
|
|
908
|
-
};
|
|
909
|
-
var OAuthInterceptorService = {
|
|
910
|
-
provide: http.HTTP_INTERCEPTORS,
|
|
911
|
-
useClass: OAuthInterceptor,
|
|
912
|
-
multi: true,
|
|
913
|
-
};
|
|
914
|
-
var defaultConfig = function (storage) {
|
|
915
|
-
return {
|
|
916
|
-
storage: storage,
|
|
917
|
-
storageKey: 'token',
|
|
918
|
-
ignorePaths: []
|
|
919
|
-
};
|
|
920
|
-
};
|
|
921
|
-
var ɵ1 = defaultConfig;
|
|
922
|
-
var OAuthModule = /** @class */ (function () {
|
|
923
|
-
function OAuthModule() {
|
|
924
|
-
}
|
|
925
|
-
OAuthModule.forRoot = function (config) {
|
|
926
|
-
return {
|
|
927
|
-
ngModule: OAuthModule,
|
|
928
|
-
providers: [
|
|
929
|
-
LocationService,
|
|
930
|
-
StorageService,
|
|
931
|
-
OAuthService,
|
|
932
|
-
OAuthInterceptorService,
|
|
933
|
-
{
|
|
934
|
-
provide: OAUTH_CONFIG,
|
|
935
|
-
useFactory: function (storage) {
|
|
936
|
-
return Object.assign(Object.assign({}, defaultConfig(storage)), config);
|
|
937
|
-
},
|
|
938
|
-
deps: [
|
|
939
|
-
STORAGE
|
|
940
|
-
]
|
|
941
|
-
}
|
|
942
|
-
]
|
|
943
|
-
};
|
|
944
|
-
};
|
|
945
|
-
return OAuthModule;
|
|
946
|
-
}());
|
|
947
|
-
OAuthModule.decorators = [
|
|
948
|
-
{ type: core.NgModule, args: [{
|
|
949
|
-
imports: [
|
|
950
|
-
common.CommonModule,
|
|
951
|
-
forms.FormsModule,
|
|
952
|
-
http.HttpClientModule,
|
|
953
|
-
router.RouterModule,
|
|
954
|
-
],
|
|
955
|
-
declarations: [OAuthLoginComponent],
|
|
956
|
-
exports: [OAuthLoginComponent],
|
|
957
|
-
providers: [
|
|
958
|
-
LocationService,
|
|
959
|
-
StorageService,
|
|
960
|
-
OAuthService,
|
|
961
|
-
OAuthInterceptorService,
|
|
962
|
-
]
|
|
963
|
-
},] }
|
|
964
|
-
];
|
|
965
|
-
|
|
966
|
-
/*
|
|
967
|
-
* Public API Surface of ngx-oauth
|
|
968
|
-
*/
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Generated bundle index. Do not edit.
|
|
972
|
-
*/
|
|
973
|
-
|
|
974
|
-
exports.LOCATION = LOCATION;
|
|
975
|
-
exports.OAUTH_CONFIG = OAUTH_CONFIG;
|
|
976
|
-
exports.OAuthInterceptor = OAuthInterceptor;
|
|
977
|
-
exports.OAuthLoginComponent = OAuthLoginComponent;
|
|
978
|
-
exports.OAuthModule = OAuthModule;
|
|
979
|
-
exports.OAuthService = OAuthService;
|
|
980
|
-
exports.SERVER_HOST = SERVER_HOST;
|
|
981
|
-
exports.SERVER_PATH = SERVER_PATH;
|
|
982
|
-
exports.STORAGE = STORAGE;
|
|
983
|
-
exports.ɵ2 = ɵ2;
|
|
984
|
-
|
|
985
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
986
|
-
|
|
987
|
-
})));
|
|
988
|
-
//# sourceMappingURL=ngx-oauth.umd.js.map
|