github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/backend/infrastructure/dmm_eikaiwa/testdata/49393_files/auto-login.js (about) 1 /******/ (function(modules) { // webpackBootstrap 2 /******/ // The module cache 3 /******/ var installedModules = {}; 4 /******/ 5 /******/ // The require function 6 /******/ function __webpack_require__(moduleId) { 7 /******/ 8 /******/ // Check if module is in cache 9 /******/ if(installedModules[moduleId]) { 10 /******/ return installedModules[moduleId].exports; 11 /******/ } 12 /******/ // Create a new module (and put it into the cache) 13 /******/ var module = installedModules[moduleId] = { 14 /******/ i: moduleId, 15 /******/ l: false, 16 /******/ exports: {} 17 /******/ }; 18 /******/ 19 /******/ // Execute the module function 20 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 /******/ 22 /******/ // Flag the module as loaded 23 /******/ module.l = true; 24 /******/ 25 /******/ // Return the exports of the module 26 /******/ return module.exports; 27 /******/ } 28 /******/ 29 /******/ 30 /******/ // expose the modules object (__webpack_modules__) 31 /******/ __webpack_require__.m = modules; 32 /******/ 33 /******/ // expose the module cache 34 /******/ __webpack_require__.c = installedModules; 35 /******/ 36 /******/ // identity function for calling harmony imports with the correct context 37 /******/ __webpack_require__.i = function(value) { return value; }; 38 /******/ 39 /******/ // define getter function for harmony exports 40 /******/ __webpack_require__.d = function(exports, name, getter) { 41 /******/ if(!__webpack_require__.o(exports, name)) { 42 /******/ Object.defineProperty(exports, name, { 43 /******/ configurable: false, 44 /******/ enumerable: true, 45 /******/ get: getter 46 /******/ }); 47 /******/ } 48 /******/ }; 49 /******/ 50 /******/ // getDefaultExport function for compatibility with non-harmony modules 51 /******/ __webpack_require__.n = function(module) { 52 /******/ var getter = module && module.__esModule ? 53 /******/ function getDefault() { return module['default']; } : 54 /******/ function getModuleExports() { return module; }; 55 /******/ __webpack_require__.d(getter, 'a', getter); 56 /******/ return getter; 57 /******/ }; 58 /******/ 59 /******/ // Object.prototype.hasOwnProperty.call 60 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 61 /******/ 62 /******/ // __webpack_public_path__ 63 /******/ __webpack_require__.p = ""; 64 /******/ 65 /******/ // Load entry module and return exports 66 /******/ return __webpack_require__(__webpack_require__.s = 3); 67 /******/ }) 68 /************************************************************************/ 69 /******/ ([ 70 /* 0 */ 71 /***/ (function(module, exports, __webpack_require__) { 72 73 "use strict"; 74 75 76 exports.__esModule = true; 77 exports['default'] = getAutoLoginUrl; 78 /** 79 * 自動ログインの制御を行う 80 * @param {string} callbackurl - ログイン後のコールバックURL 81 * @param {object} document - ブラウザオブジェクト 82 * @param {string|null} hasAltHashCookie - Cookie:has_althashの中身 83 * @param {string|null} hasAltTimeCookie - Cookie:has_alttimeの中身 84 * @param {'dev'|'stg'|'prd'} accountsEnv - リダイレクトするアカウントサービスの環境 85 * @return {string|null} リダイレクト先URL, リダイレクトしない場合はnull 86 */ 87 function getAutoLoginUrl(callbackUrl, document, hasAltHashCookie, hasAltTimeCookie) { 88 var accountsEnv = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "prd"; 89 90 var getPrefix = function getPrefix(env) { 91 if (env === 'dev') { 92 return 'dev-'; 93 } 94 if (env === 'stg') { 95 return 'stg-'; 96 } 97 return ''; 98 }; 99 100 var getRedirectUrl = function getRedirectUrl(url, env) { 101 var tld = document.domain.replace(/^.*\.(com|jp)$/, '$1'); 102 var domain = tld === 'jp' ? 'co.jp' : 'com'; 103 return 'https://' + String(getPrefix(env)) + 'accounts.dmm.' + domain + '/service/login/token/=/path=' + String(url); 104 }; 105 106 var validateArgs = function validateArgs() { 107 return typeof callbackUrl === 'string'; 108 }; 109 110 var canRedirect = function canRedirect(hasAltHash, hasAltTime) { 111 return hasAltHash && !hasAltTime; 112 }; 113 114 if (validateArgs() === false) { 115 return null; 116 } 117 118 if (canRedirect(hasAltHashCookie, hasAltTimeCookie)) { 119 return getRedirectUrl(callbackUrl, accountsEnv); 120 } 121 return null; 122 } 123 124 /***/ }), 125 /* 1 */ 126 /***/ (function(module, exports, __webpack_require__) { 127 128 "use strict"; 129 130 131 var _browserCookies = __webpack_require__(2); 132 133 var _browserCookies2 = _interopRequireDefault(_browserCookies); 134 135 var _index = __webpack_require__(0); 136 137 var _index2 = _interopRequireDefault(_index); 138 139 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 140 141 (function () { 142 var autoLoginElement = document.getElementById('auto-login'); 143 var path = autoLoginElement.getAttribute('data-encoded'); 144 var hasAltHash = _browserCookies2['default'].get('has_althash'); 145 var hasAltTime = _browserCookies2['default'].get('has_alttime'); 146 var href = (0, _index2['default'])(path, document, hasAltHash, hasAltTime); 147 if (href != null) { 148 location.href = href; 149 } 150 })(); 151 152 /***/ }), 153 /* 2 */ 154 /***/ (function(module, exports) { 155 156 exports.defaults = {}; 157 158 exports.set = function(name, value, options) { 159 // Retrieve options and defaults 160 var opts = options || {}; 161 var defaults = exports.defaults; 162 163 // Apply default value for unspecified options 164 var expires = opts.expires || defaults.expires; 165 var domain = opts.domain || defaults.domain; 166 var path = opts.path !== undefined ? opts.path : (defaults.path !== undefined ? defaults.path : '/'); 167 var secure = opts.secure !== undefined ? opts.secure : defaults.secure; 168 var httponly = opts.httponly !== undefined ? opts.httponly : defaults.httponly; 169 var samesite = opts.samesite !== undefined ? opts.samesite : defaults.samesite; 170 171 // Determine cookie expiration date 172 // If succesful the result will be a valid Date, otherwise it will be an invalid Date or false(ish) 173 var expDate = expires ? new Date( 174 // in case expires is an integer, it should specify the number of days till the cookie expires 175 typeof expires === 'number' ? new Date().getTime() + (expires * 864e5) : 176 // else expires should be either a Date object or in a format recognized by Date.parse() 177 expires 178 ) : 0; 179 180 // Set cookie 181 document.cookie = name.replace(/[^+#$&^`|]/g, encodeURIComponent) // Encode cookie name 182 .replace('(', '%28') 183 .replace(')', '%29') + 184 '=' + value.replace(/[^+#$&/:<-\[\]-}]/g, encodeURIComponent) + // Encode cookie value (RFC6265) 185 (expDate && expDate.getTime() >= 0 ? ';expires=' + expDate.toUTCString() : '') + // Add expiration date 186 (domain ? ';domain=' + domain : '') + // Add domain 187 (path ? ';path=' + path : '') + // Add path 188 (secure ? ';secure' : '') + // Add secure option 189 (httponly ? ';httponly' : '') + // Add httponly option 190 (samesite ? ';samesite=' + samesite : ''); // Add samesite option 191 }; 192 193 exports.get = function(name) { 194 var cookies = document.cookie.split(';'); 195 196 // Iterate all cookies 197 while(cookies.length) { 198 var cookie = cookies.pop(); 199 200 // Determine separator index ("name=value") 201 var separatorIndex = cookie.indexOf('='); 202 203 // IE<11 emits the equal sign when the cookie value is empty 204 separatorIndex = separatorIndex < 0 ? cookie.length : separatorIndex; 205 206 var cookie_name = decodeURIComponent(cookie.slice(0, separatorIndex).replace(/^\s+/, '')); 207 208 // Return cookie value if the name matches 209 if (cookie_name === name) { 210 return decodeURIComponent(cookie.slice(separatorIndex + 1)); 211 } 212 } 213 214 // Return `null` as the cookie was not found 215 return null; 216 }; 217 218 exports.erase = function(name, options) { 219 exports.set(name, '', { 220 expires: -1, 221 domain: options && options.domain, 222 path: options && options.path, 223 secure: 0, 224 httponly: 0} 225 ); 226 }; 227 228 exports.all = function() { 229 var all = {}; 230 var cookies = document.cookie.split(';'); 231 232 // Iterate all cookies 233 while(cookies.length) { 234 var cookie = cookies.pop(); 235 236 // Determine separator index ("name=value") 237 var separatorIndex = cookie.indexOf('='); 238 239 // IE<11 emits the equal sign when the cookie value is empty 240 separatorIndex = separatorIndex < 0 ? cookie.length : separatorIndex; 241 242 // add the cookie name and value to the `all` object 243 var cookie_name = decodeURIComponent(cookie.slice(0, separatorIndex).replace(/^\s+/, '')); 244 all[cookie_name] = decodeURIComponent(cookie.slice(separatorIndex + 1)); 245 } 246 247 return all; 248 }; 249 250 251 /***/ }), 252 /* 3 */ 253 /***/ (function(module, exports, __webpack_require__) { 254 255 __webpack_require__(0); 256 module.exports = __webpack_require__(1); 257 258 259 /***/ }) 260 /******/ ]);