@edx/frontend-platform 3.6.0 → 3.6.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/analytics/MockAnalyticsService.js +6 -19
- package/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js +53 -57
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/analytics/index.js.map +1 -1
- package/analytics/interface.js +9 -9
- package/analytics/interface.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js +36 -58
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js +105 -150
- package/auth/AxiosJwtAuthService.js.map +1 -1
- package/auth/AxiosJwtTokenService.js +101 -148
- package/auth/AxiosJwtTokenService.js.map +1 -1
- package/auth/LocalForageCache.js +89 -108
- package/auth/LocalForageCache.js.map +1 -1
- package/auth/MockAuthService.js +10 -35
- package/auth/MockAuthService.js.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js +35 -50
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.js +33 -47
- package/auth/interceptors/createJwtTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js +15 -27
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +1 -1
- package/auth/interceptors/createRetryInterceptor.js +75 -105
- package/auth/interceptors/createRetryInterceptor.js.map +1 -1
- package/auth/interface.js +41 -58
- package/auth/interface.js.map +1 -1
- package/auth/utils.js +22 -40
- package/auth/utils.js.map +1 -1
- package/config.js +6 -7
- package/config.js.map +1 -1
- package/constants.js +8 -8
- package/constants.js.map +1 -1
- package/i18n/countries.js +9 -15
- package/i18n/countries.js.map +1 -1
- package/i18n/index.js +1 -0
- package/i18n/index.js.map +1 -1
- package/i18n/injectIntlWithShim.js +4 -28
- package/i18n/injectIntlWithShim.js.map +1 -1
- package/i18n/languages.js +11 -17
- package/i18n/languages.js.map +1 -1
- package/i18n/lib.js +64 -56
- package/i18n/lib.js.map +1 -1
- package/i18n/scripts/transifex-utils.js +5 -20
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/index.js.map +1 -1
- package/initialize.js +176 -228
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js +5 -9
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js +9 -33
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/index.js.map +1 -1
- package/logging/interface.js +7 -6
- package/logging/interface.js.map +1 -1
- package/package.json +4 -4
- package/pubSub.js +4 -3
- package/pubSub.js.map +1 -1
- package/react/AppContext.js +1 -1
- package/react/AppContext.js.map +1 -1
- package/react/AppProvider.js +13 -23
- package/react/AppProvider.js.map +1 -1
- package/react/AuthenticatedPageRoute.js +5 -13
- package/react/AuthenticatedPageRoute.js.map +1 -1
- package/react/ErrorBoundary.js +4 -21
- package/react/ErrorBoundary.js.map +1 -1
- package/react/ErrorPage.js +7 -17
- package/react/ErrorPage.js.map +1 -1
- package/react/LoginRedirect.js +1 -1
- package/react/LoginRedirect.js.map +1 -1
- package/react/OptionalReduxProvider.js +2 -4
- package/react/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js +3 -3
- package/react/PageRoute.js.map +1 -1
- package/react/hooks.js +2 -6
- package/react/hooks.js.map +1 -1
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/testing/index.js +1 -0
- package/testing/index.js.map +1 -1
- package/testing/initializeMockApp.js +11 -11
- package/testing/initializeMockApp.js.map +1 -1
- package/testing/mockMessages.js.map +1 -1
- package/utils.js +15 -24
- package/utils.js.map +1 -1
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
10
|
-
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
11
6
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
-
|
|
13
7
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
-
|
|
15
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
|
|
17
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
18
|
-
|
|
9
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
19
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
|
-
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
13
|
import axios from 'axios';
|
|
22
14
|
import PropTypes from 'prop-types';
|
|
23
15
|
import { logFrontendAuthError } from './utils';
|
|
@@ -43,11 +35,11 @@ var optionsPropTypes = {
|
|
|
43
35
|
logInfo: PropTypes.func.isRequired
|
|
44
36
|
}).isRequired
|
|
45
37
|
};
|
|
38
|
+
|
|
46
39
|
/**
|
|
47
40
|
* @implements {AuthService}
|
|
48
41
|
* @memberof module:Auth
|
|
49
42
|
*/
|
|
50
|
-
|
|
51
43
|
var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
52
44
|
/**
|
|
53
45
|
* @param {Object} options
|
|
@@ -63,9 +55,7 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
63
55
|
*/
|
|
64
56
|
function AxiosJwtAuthService(options) {
|
|
65
57
|
var _this = this;
|
|
66
|
-
|
|
67
58
|
_classCallCheck(this, AxiosJwtAuthService);
|
|
68
|
-
|
|
69
59
|
this.authenticatedHttpClient = null;
|
|
70
60
|
this.httpClient = null;
|
|
71
61
|
this.cachedAuthenticatedHttpClient = null;
|
|
@@ -89,23 +79,20 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
89
79
|
logFrontendAuthError(_this.loggingService, "configureCache failed with error: ".concat(e.message));
|
|
90
80
|
})["finally"](function () {
|
|
91
81
|
_this.middleware = options.middleware;
|
|
92
|
-
|
|
93
82
|
_this.applyMiddleware(options.middleware);
|
|
94
83
|
});
|
|
95
84
|
}
|
|
85
|
+
|
|
96
86
|
/**
|
|
97
87
|
* Applies middleware to the axios instances in this service.
|
|
98
88
|
*
|
|
99
89
|
* @param {Array} middleware Middleware to apply.
|
|
100
90
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
91
|
_createClass(AxiosJwtAuthService, [{
|
|
104
92
|
key: "applyMiddleware",
|
|
105
93
|
value: function applyMiddleware() {
|
|
106
94
|
var middleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
107
95
|
var clients = [this.authenticatedHttpClient, this.httpClient, this.cachedAuthenticatedHttpClient, this.cachedHttpClient];
|
|
108
|
-
|
|
109
96
|
try {
|
|
110
97
|
middleware.forEach(function (middlewareFn) {
|
|
111
98
|
clients.forEach(function (client) {
|
|
@@ -117,6 +104,7 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
117
104
|
throw error;
|
|
118
105
|
}
|
|
119
106
|
}
|
|
107
|
+
|
|
120
108
|
/**
|
|
121
109
|
* Gets the authenticated HTTP client for the service. This is an axios instance.
|
|
122
110
|
*
|
|
@@ -127,18 +115,16 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
127
115
|
* @returns {HttpClient} A configured axios http client which can be used for authenticated
|
|
128
116
|
* requests.
|
|
129
117
|
*/
|
|
130
|
-
|
|
131
118
|
}, {
|
|
132
119
|
key: "getAuthenticatedHttpClient",
|
|
133
120
|
value: function getAuthenticatedHttpClient() {
|
|
134
121
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
135
|
-
|
|
136
122
|
if (options.useCache) {
|
|
137
123
|
return this.cachedAuthenticatedHttpClient;
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
return this.authenticatedHttpClient;
|
|
141
126
|
}
|
|
127
|
+
|
|
142
128
|
/**
|
|
143
129
|
* Gets the unauthenticated HTTP client for the service. This is an axios instance.
|
|
144
130
|
*
|
|
@@ -147,40 +133,38 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
147
133
|
* with the returned client.
|
|
148
134
|
* @returns {HttpClient} A configured axios http client.
|
|
149
135
|
*/
|
|
150
|
-
|
|
151
136
|
}, {
|
|
152
137
|
key: "getHttpClient",
|
|
153
138
|
value: function getHttpClient() {
|
|
154
139
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
155
|
-
|
|
156
140
|
if (options.useCache) {
|
|
157
141
|
return this.cachedHttpClient;
|
|
158
142
|
}
|
|
159
|
-
|
|
160
143
|
return this.httpClient;
|
|
161
144
|
}
|
|
145
|
+
|
|
162
146
|
/**
|
|
163
147
|
* Used primarily for testing.
|
|
164
148
|
*
|
|
165
149
|
* @ignore
|
|
166
150
|
*/
|
|
167
|
-
|
|
168
151
|
}, {
|
|
169
152
|
key: "getJwtTokenService",
|
|
170
153
|
value: function getJwtTokenService() {
|
|
171
154
|
return this.jwtTokenService;
|
|
172
155
|
}
|
|
156
|
+
|
|
173
157
|
/**
|
|
174
158
|
* Used primarily for testing.
|
|
175
159
|
*
|
|
176
160
|
* @ignore
|
|
177
161
|
*/
|
|
178
|
-
|
|
179
162
|
}, {
|
|
180
163
|
key: "getCsrfTokenService",
|
|
181
164
|
value: function getCsrfTokenService() {
|
|
182
165
|
return this.csrfTokenService;
|
|
183
166
|
}
|
|
167
|
+
|
|
184
168
|
/**
|
|
185
169
|
* Builds a URL to the login page with a post-login redirect URL attached as a query parameter.
|
|
186
170
|
*
|
|
@@ -191,25 +175,25 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
191
175
|
*
|
|
192
176
|
* @param {string} redirectUrl The URL the user should be redirected to after logging in.
|
|
193
177
|
*/
|
|
194
|
-
|
|
195
178
|
}, {
|
|
196
179
|
key: "getLoginRedirectUrl",
|
|
197
180
|
value: function getLoginRedirectUrl() {
|
|
198
181
|
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.BASE_URL;
|
|
199
182
|
return "".concat(this.config.LOGIN_URL, "?next=").concat(encodeURIComponent(redirectUrl));
|
|
200
183
|
}
|
|
184
|
+
|
|
201
185
|
/**
|
|
202
186
|
* Redirects the user to the login page.
|
|
203
187
|
*
|
|
204
188
|
* @param {string} redirectUrl The URL the user should be redirected to after logging in.
|
|
205
189
|
*/
|
|
206
|
-
|
|
207
190
|
}, {
|
|
208
191
|
key: "redirectToLogin",
|
|
209
192
|
value: function redirectToLogin() {
|
|
210
193
|
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.BASE_URL;
|
|
211
194
|
global.location.assign(this.getLoginRedirectUrl(redirectUrl));
|
|
212
195
|
}
|
|
196
|
+
|
|
213
197
|
/**
|
|
214
198
|
* Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.
|
|
215
199
|
*
|
|
@@ -220,48 +204,48 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
220
204
|
*
|
|
221
205
|
* @param {string} redirectUrl The URL the user should be redirected to after logging out.
|
|
222
206
|
*/
|
|
223
|
-
|
|
224
207
|
}, {
|
|
225
208
|
key: "getLogoutRedirectUrl",
|
|
226
209
|
value: function getLogoutRedirectUrl() {
|
|
227
210
|
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.BASE_URL;
|
|
228
211
|
return "".concat(this.config.LOGOUT_URL, "?redirect_url=").concat(encodeURIComponent(redirectUrl));
|
|
229
212
|
}
|
|
213
|
+
|
|
230
214
|
/**
|
|
231
215
|
* Redirects the user to the logout page.
|
|
232
216
|
*
|
|
233
217
|
* @param {string} redirectUrl The URL the user should be redirected to after logging out.
|
|
234
218
|
*/
|
|
235
|
-
|
|
236
219
|
}, {
|
|
237
220
|
key: "redirectToLogout",
|
|
238
221
|
value: function redirectToLogout() {
|
|
239
222
|
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.BASE_URL;
|
|
240
223
|
global.location.assign(this.getLogoutRedirectUrl(redirectUrl));
|
|
241
224
|
}
|
|
225
|
+
|
|
242
226
|
/**
|
|
243
227
|
* If it exists, returns the user data representing the currently authenticated user. If the
|
|
244
228
|
* user is anonymous, returns null.
|
|
245
229
|
*
|
|
246
230
|
* @returns {UserData|null}
|
|
247
231
|
*/
|
|
248
|
-
|
|
249
232
|
}, {
|
|
250
233
|
key: "getAuthenticatedUser",
|
|
251
234
|
value: function getAuthenticatedUser() {
|
|
252
235
|
return this.authenticatedUser;
|
|
253
236
|
}
|
|
237
|
+
|
|
254
238
|
/**
|
|
255
239
|
* Sets the authenticated user to the provided value.
|
|
256
240
|
*
|
|
257
241
|
* @param {UserData} authUser
|
|
258
242
|
*/
|
|
259
|
-
|
|
260
243
|
}, {
|
|
261
244
|
key: "setAuthenticatedUser",
|
|
262
245
|
value: function setAuthenticatedUser(authUser) {
|
|
263
246
|
this.authenticatedUser = authUser;
|
|
264
247
|
}
|
|
248
|
+
|
|
265
249
|
/**
|
|
266
250
|
* Reads the authenticated user's access token. Resolves to null if the user is
|
|
267
251
|
* unauthenticated.
|
|
@@ -269,52 +253,43 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
269
253
|
* @returns {Promise<UserData>|Promise<null>} Resolves to the user's access token if they are
|
|
270
254
|
* logged in.
|
|
271
255
|
*/
|
|
272
|
-
|
|
273
256
|
}, {
|
|
274
257
|
key: "fetchAuthenticatedUser",
|
|
275
258
|
value: function () {
|
|
276
259
|
var _fetchAuthenticatedUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
277
260
|
var options,
|
|
278
|
-
|
|
279
|
-
|
|
261
|
+
decodedAccessToken,
|
|
262
|
+
_args = arguments;
|
|
280
263
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
281
|
-
while (1) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return _context.abrupt("return", this.getAuthenticatedUser());
|
|
305
|
-
|
|
306
|
-
case 6:
|
|
307
|
-
case "end":
|
|
308
|
-
return _context.stop();
|
|
309
|
-
}
|
|
264
|
+
while (1) switch (_context.prev = _context.next) {
|
|
265
|
+
case 0:
|
|
266
|
+
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
267
|
+
_context.next = 3;
|
|
268
|
+
return this.jwtTokenService.getJwtToken(options.forceRefresh || false);
|
|
269
|
+
case 3:
|
|
270
|
+
decodedAccessToken = _context.sent;
|
|
271
|
+
if (decodedAccessToken !== null) {
|
|
272
|
+
this.setAuthenticatedUser({
|
|
273
|
+
email: decodedAccessToken.email,
|
|
274
|
+
userId: decodedAccessToken.user_id,
|
|
275
|
+
username: decodedAccessToken.preferred_username,
|
|
276
|
+
roles: decodedAccessToken.roles || [],
|
|
277
|
+
administrator: decodedAccessToken.administrator,
|
|
278
|
+
name: decodedAccessToken.name
|
|
279
|
+
});
|
|
280
|
+
} else {
|
|
281
|
+
this.setAuthenticatedUser(null);
|
|
282
|
+
}
|
|
283
|
+
return _context.abrupt("return", this.getAuthenticatedUser());
|
|
284
|
+
case 6:
|
|
285
|
+
case "end":
|
|
286
|
+
return _context.stop();
|
|
310
287
|
}
|
|
311
288
|
}, _callee, this);
|
|
312
289
|
}));
|
|
313
|
-
|
|
314
290
|
function fetchAuthenticatedUser() {
|
|
315
291
|
return _fetchAuthenticatedUser.apply(this, arguments);
|
|
316
292
|
}
|
|
317
|
-
|
|
318
293
|
return fetchAuthenticatedUser;
|
|
319
294
|
}()
|
|
320
295
|
/**
|
|
@@ -325,63 +300,51 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
325
300
|
* authenticated.
|
|
326
301
|
* @returns {Promise<UserData>}
|
|
327
302
|
*/
|
|
328
|
-
|
|
329
303
|
}, {
|
|
330
304
|
key: "ensureAuthenticatedUser",
|
|
331
305
|
value: function () {
|
|
332
306
|
var _ensureAuthenticatedUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
333
307
|
var redirectUrl,
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
308
|
+
isRedirectFromLoginPage,
|
|
309
|
+
redirectLoopError,
|
|
310
|
+
unauthorizedError,
|
|
311
|
+
_args2 = arguments;
|
|
338
312
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
339
|
-
while (1) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
throw unauthorizedError;
|
|
369
|
-
|
|
370
|
-
case 13:
|
|
371
|
-
return _context2.abrupt("return", this.getAuthenticatedUser());
|
|
372
|
-
|
|
373
|
-
case 14:
|
|
374
|
-
case "end":
|
|
375
|
-
return _context2.stop();
|
|
376
|
-
}
|
|
313
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
314
|
+
case 0:
|
|
315
|
+
redirectUrl = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : this.config.BASE_URL;
|
|
316
|
+
_context2.next = 3;
|
|
317
|
+
return this.fetchAuthenticatedUser();
|
|
318
|
+
case 3:
|
|
319
|
+
if (!(this.getAuthenticatedUser() === null)) {
|
|
320
|
+
_context2.next = 13;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
isRedirectFromLoginPage = global.document.referrer && global.document.referrer.startsWith(this.config.LOGIN_URL);
|
|
324
|
+
if (!isRedirectFromLoginPage) {
|
|
325
|
+
_context2.next = 9;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
redirectLoopError = new Error('Redirect from login page. Rejecting to avoid infinite redirect loop.');
|
|
329
|
+
logFrontendAuthError(this.loggingService, redirectLoopError);
|
|
330
|
+
throw redirectLoopError;
|
|
331
|
+
case 9:
|
|
332
|
+
// The user is not authenticated, send them to the login page.
|
|
333
|
+
this.redirectToLogin(redirectUrl);
|
|
334
|
+
unauthorizedError = new Error('Failed to ensure the user is authenticated');
|
|
335
|
+
unauthorizedError.isRedirecting = true;
|
|
336
|
+
throw unauthorizedError;
|
|
337
|
+
case 13:
|
|
338
|
+
return _context2.abrupt("return", this.getAuthenticatedUser());
|
|
339
|
+
case 14:
|
|
340
|
+
case "end":
|
|
341
|
+
return _context2.stop();
|
|
377
342
|
}
|
|
378
343
|
}, _callee2, this);
|
|
379
344
|
}));
|
|
380
|
-
|
|
381
345
|
function ensureAuthenticatedUser() {
|
|
382
346
|
return _ensureAuthenticatedUser.apply(this, arguments);
|
|
383
347
|
}
|
|
384
|
-
|
|
385
348
|
return ensureAuthenticatedUser;
|
|
386
349
|
}()
|
|
387
350
|
/**
|
|
@@ -397,42 +360,33 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
397
360
|
*
|
|
398
361
|
* @returns {Promise<null>}
|
|
399
362
|
*/
|
|
400
|
-
|
|
401
363
|
}, {
|
|
402
364
|
key: "hydrateAuthenticatedUser",
|
|
403
365
|
value: function () {
|
|
404
366
|
var _hydrateAuthenticatedUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
405
367
|
var user, response;
|
|
406
368
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
407
|
-
while (1) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
this.setAuthenticatedUser(_objectSpread(_objectSpread({}, user), camelCaseObject(response.data)));
|
|
423
|
-
|
|
424
|
-
case 6:
|
|
425
|
-
case "end":
|
|
426
|
-
return _context3.stop();
|
|
427
|
-
}
|
|
369
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
370
|
+
case 0:
|
|
371
|
+
user = this.getAuthenticatedUser();
|
|
372
|
+
if (!(user !== null)) {
|
|
373
|
+
_context3.next = 6;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
_context3.next = 4;
|
|
377
|
+
return this.authenticatedHttpClient.get("".concat(this.config.LMS_BASE_URL, "/api/user/v1/accounts/").concat(user.username));
|
|
378
|
+
case 4:
|
|
379
|
+
response = _context3.sent;
|
|
380
|
+
this.setAuthenticatedUser(_objectSpread(_objectSpread({}, user), camelCaseObject(response.data)));
|
|
381
|
+
case 6:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context3.stop();
|
|
428
384
|
}
|
|
429
385
|
}, _callee3, this);
|
|
430
386
|
}));
|
|
431
|
-
|
|
432
387
|
function hydrateAuthenticatedUser() {
|
|
433
388
|
return _hydrateAuthenticatedUser.apply(this, arguments);
|
|
434
389
|
}
|
|
435
|
-
|
|
436
390
|
return hydrateAuthenticatedUser;
|
|
437
391
|
}()
|
|
438
392
|
/**
|
|
@@ -445,58 +399,59 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
|
|
|
445
399
|
* @param {string} [config.CSRF_TOKEN_API_PATH]
|
|
446
400
|
* @returns {HttpClient} A configured Axios HTTP client.
|
|
447
401
|
*/
|
|
448
|
-
|
|
449
402
|
}, {
|
|
450
403
|
key: "addAuthenticationToHttpClient",
|
|
451
404
|
value: function addAuthenticationToHttpClient(newHttpClient) {
|
|
452
|
-
var httpClient = Object.create(newHttpClient);
|
|
405
|
+
var httpClient = Object.create(newHttpClient);
|
|
406
|
+
// Set withCredentials to true. Enables cross-site Access-Control requests
|
|
453
407
|
// to be made using cookies, authorization headers or TLS client
|
|
454
408
|
// certificates. More on MDN:
|
|
455
409
|
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
|
|
410
|
+
httpClient.defaults.withCredentials = true;
|
|
411
|
+
|
|
412
|
+
// Axios interceptors
|
|
456
413
|
|
|
457
|
-
httpClient.defaults.withCredentials = true; // Axios interceptors
|
|
458
414
|
// The JWT access token interceptor attempts to refresh the user's jwt token
|
|
459
415
|
// before any request unless the isPublic flag is set on the request config.
|
|
460
|
-
|
|
461
416
|
var refreshAccessTokenInterceptor = createJwtTokenProviderInterceptor({
|
|
462
417
|
jwtTokenService: this.jwtTokenService,
|
|
463
418
|
shouldSkip: function shouldSkip(axiosRequestConfig) {
|
|
464
419
|
return axiosRequestConfig.isPublic;
|
|
465
420
|
}
|
|
466
|
-
});
|
|
421
|
+
});
|
|
422
|
+
// The CSRF token intercepter fetches and caches a csrf token for any post,
|
|
467
423
|
// put, patch, or delete request. That token is then added to the request
|
|
468
424
|
// headers.
|
|
469
|
-
|
|
470
425
|
var attachCsrfTokenInterceptor = createCsrfTokenProviderInterceptor({
|
|
471
426
|
csrfTokenService: this.csrfTokenService,
|
|
472
427
|
CSRF_TOKEN_API_PATH: this.config.CSRF_TOKEN_API_PATH,
|
|
473
428
|
shouldSkip: function shouldSkip(axiosRequestConfig) {
|
|
474
429
|
var method = axiosRequestConfig.method,
|
|
475
|
-
|
|
430
|
+
isCsrfExempt = axiosRequestConfig.isCsrfExempt;
|
|
476
431
|
var CSRF_PROTECTED_METHODS = ['post', 'put', 'patch', 'delete'];
|
|
477
432
|
return isCsrfExempt || !CSRF_PROTECTED_METHODS.includes(method);
|
|
478
433
|
}
|
|
479
434
|
});
|
|
480
435
|
var processAxiosRequestErrorInterceptor = createProcessAxiosRequestErrorInterceptor({
|
|
481
436
|
loggingService: this.loggingService
|
|
482
|
-
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// Request interceptors: Axios runs the interceptors in reverse order from
|
|
483
440
|
// how they are listed. After fetching csrf tokens no longer require jwt
|
|
484
441
|
// authentication, it won't matter which happens first. This change is
|
|
485
442
|
// coming soon in edx-platform. Nov. 2019
|
|
486
|
-
|
|
487
443
|
httpClient.interceptors.request.use(attachCsrfTokenInterceptor);
|
|
488
|
-
httpClient.interceptors.request.use(refreshAccessTokenInterceptor);
|
|
489
|
-
// object at error.customAttributes
|
|
444
|
+
httpClient.interceptors.request.use(refreshAccessTokenInterceptor);
|
|
490
445
|
|
|
446
|
+
// Response interceptor: moves axios response error data into the error
|
|
447
|
+
// object at error.customAttributes
|
|
491
448
|
httpClient.interceptors.response.use(function (response) {
|
|
492
449
|
return response;
|
|
493
450
|
}, processAxiosRequestErrorInterceptor);
|
|
494
451
|
return httpClient;
|
|
495
452
|
}
|
|
496
453
|
}]);
|
|
497
|
-
|
|
498
454
|
return AxiosJwtAuthService;
|
|
499
455
|
}();
|
|
500
|
-
|
|
501
456
|
export default AxiosJwtAuthService;
|
|
502
457
|
//# sourceMappingURL=AxiosJwtAuthService.js.map
|