Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
+115
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
var BaseConfig = {
|
||||
earlyRefresh: 30
|
||||
};
|
||||
|
||||
var getAuthorizationHeader = function getAuthorizationHeader(token) {
|
||||
return "Bearer ".concat(token);
|
||||
};
|
||||
/**
|
||||
* Requests a short term token from the DDB Auth API using the Cobalt session cookie to authorize the user
|
||||
* @param {string} authUrl The URL to the cobalt-token auth endpoint
|
||||
* @param {boolean} throwOnHttpStatusError Option to transform error status codes (4xx/5xx) to exceptions
|
||||
* @returns {Promise<object>} A promise that resolves to the JSON object returned by the Auth API
|
||||
*/
|
||||
|
||||
|
||||
var getShortTermToken = function getShortTermToken(_ref) {
|
||||
var _ref$authUrl = _ref.authUrl,
|
||||
authUrl = _ref$authUrl === void 0 ? 'https://auth-service.dndbeyond.com/v1/cobalt-token' : _ref$authUrl,
|
||||
_ref$throwOnHttpStatu = _ref.throwOnHttpStatusError,
|
||||
throwOnHttpStatusError = _ref$throwOnHttpStatu === void 0 ? true : _ref$throwOnHttpStatu;
|
||||
return fetch(authUrl, {
|
||||
credentials: 'include',
|
||||
method: 'POST'
|
||||
}).then(function (response) {
|
||||
// eslint-disable-next-line no-magic-numbers, `Copied from https://github.com/whatwg/fetch/issues/18#issuecomment-68273579`
|
||||
if (throwOnHttpStatusError && response.status >= 400 && response.status < 600) {
|
||||
throw new Error('Bad response from server');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Makes a getter function that will return a promise that resolves to a short term token (JWT) if signed in, null otherwise
|
||||
* @param {object} options Options object that is passed on to internally called methods
|
||||
* @returns {function(): (Promise<object>)} A promise that resolves to a short term token (JWT) if signed in, null otherwise
|
||||
*/
|
||||
|
||||
|
||||
var makeGetShortTermToken = function makeGetShortTermToken(options) {
|
||||
var _options$earlyRefresh = options.earlyRefresh,
|
||||
earlyRefresh = _options$earlyRefresh === void 0 ? BaseConfig.earlyRefresh : _options$earlyRefresh,
|
||||
_options$getShortTerm = options.getShortTermTokenFunc,
|
||||
getShortTermTokenFunc = _options$getShortTerm === void 0 ? getShortTermToken : _options$getShortTerm;
|
||||
var timeOfRequest;
|
||||
var lastSessionToken;
|
||||
var timeToLive = 0;
|
||||
var pendingRequest = null;
|
||||
return function () {
|
||||
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
||||
_ref2$ignoreAnonymous = _ref2.ignoreAnonymousTimeToLive,
|
||||
ignoreAnonymousTimeToLive = _ref2$ignoreAnonymous === void 0 ? false : _ref2$ignoreAnonymous;
|
||||
|
||||
if (pendingRequest) {
|
||||
return pendingRequest;
|
||||
}
|
||||
|
||||
var shouldUseTimeToLive = ignoreAnonymousTimeToLive ? lastSessionToken != null : true;
|
||||
|
||||
if (shouldUseTimeToLive && timeToLive && timeOfRequest + timeToLive > Date.now()) {
|
||||
return new Promise(function (resolve) {
|
||||
return resolve(lastSessionToken);
|
||||
});
|
||||
}
|
||||
|
||||
timeOfRequest = Date.now();
|
||||
pendingRequest = getShortTermTokenFunc(options).then(function (data) {
|
||||
lastSessionToken = data.token; // eslint-disable-next-line no-magic-numbers, "multiply by 1000 because TTL is measured in seconds"
|
||||
|
||||
timeToLive = (data.ttl - earlyRefresh) * 1000;
|
||||
pendingRequest = null;
|
||||
return data.token;
|
||||
})["catch"](function (error) {
|
||||
timeToLive = 0;
|
||||
lastSessionToken = null;
|
||||
pendingRequest = null;
|
||||
throw error;
|
||||
});
|
||||
return pendingRequest;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Makes a getter function that will return a promise that resolves to auth headers if signed in, an empty object otherwise
|
||||
* @param {object} options Options object that is passed on to internally called methods
|
||||
* @param {function} options.madeGetShortTermToken Optional function to use instead of calling makeGetShortTermToken so the same function instance can be shared
|
||||
* @returns {function(): (Promise<object>)} A promise that resolves to a headers object if signed in, an empty object otherwise
|
||||
*/
|
||||
|
||||
|
||||
var makeGetAuthorizationHeaders = function makeGetAuthorizationHeaders(options) {
|
||||
var getShortTermTokenFunc = options.madeGetShortTermToken || makeGetShortTermToken(options);
|
||||
return function () {
|
||||
return getShortTermTokenFunc.apply(void 0, arguments).then(function (shortTermToken) {
|
||||
if (!shortTermToken) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
Authorization: getAuthorizationHeader(shortTermToken)
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var _default = {
|
||||
makeGetShortTermToken: makeGetShortTermToken,
|
||||
makeGetAuthorizationHeaders: makeGetAuthorizationHeaders
|
||||
};
|
||||
exports["default"] = _default;
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
// Manually implement reselect/createSelector without memoization so we don't force the dependency,
|
||||
// because this object is simple enough to not need memoization and the interface makes it easier to share null handling logic
|
||||
var createSelector = function createSelector(deps, selector) {
|
||||
return function (state) {
|
||||
return selector.apply(void 0, _toConsumableArray(deps.map(function (dep) {
|
||||
return dep(state);
|
||||
})));
|
||||
};
|
||||
};
|
||||
|
||||
var getUser = function getUser(user) {
|
||||
return user || {};
|
||||
};
|
||||
|
||||
var getId = createSelector([getUser], function (_ref) {
|
||||
var id = _ref.id;
|
||||
return id;
|
||||
});
|
||||
var getName = createSelector([getUser], function (_ref2) {
|
||||
var name = _ref2.name;
|
||||
return name;
|
||||
});
|
||||
var getRoles = createSelector([getUser], function (_ref3) {
|
||||
var roles = _ref3.roles;
|
||||
return roles || [];
|
||||
});
|
||||
var getSubscriptions = createSelector([getUser], function (_ref4) {
|
||||
var subscriptions = _ref4.subscriptions;
|
||||
return subscriptions || [];
|
||||
});
|
||||
var getSubscriptionTier = createSelector([getUser], function (_ref5) {
|
||||
var subscriptionTier = _ref5.subscriptionTier;
|
||||
return subscriptionTier;
|
||||
});
|
||||
/**
|
||||
* Converts a decoded JWT object to a simple user object
|
||||
* @param {object} jwt, A decoded JWT from the Auth API
|
||||
* @returns {object} A user object with simple property names instead of JWT schema links
|
||||
*/
|
||||
|
||||
var jwtToUser = function jwtToUser(jwt) {
|
||||
return jwt ? {
|
||||
id: jwt['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'],
|
||||
name: jwt['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'],
|
||||
roles: jwt['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'],
|
||||
subscription: jwt['http://schemas.dndbeyond.com/ws/2019/08/identity/claims/subscriber'],
|
||||
subscriptionTier: jwt['http://schemas.dndbeyond.com/ws/2019/08/identity/claims/subscriptiontier'],
|
||||
avatarUrl: jwt.avatarUrl
|
||||
} : null;
|
||||
};
|
||||
|
||||
var _default = {
|
||||
getId: getId,
|
||||
getName: getName,
|
||||
getRoles: getRoles,
|
||||
getSubscriptions: getSubscriptions,
|
||||
getSubscriptionTier: getSubscriptionTier,
|
||||
jwtToUser: jwtToUser
|
||||
};
|
||||
exports["default"] = _default;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "AuthUtils", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _AuthUtils["default"];
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "UserUtils", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _UserUtils["default"];
|
||||
}
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _AuthUtils = _interopRequireDefault(require("./AuthUtils"));
|
||||
|
||||
var _UserUtils = _interopRequireDefault(require("./UserUtils"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
// Export AuthUtils as default for backwards compatibility
|
||||
var _default = _AuthUtils["default"];
|
||||
exports["default"] = _default;
|
||||
Reference in New Issue
Block a user