diff --git a/bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js b/bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js index 4a471baa7c607e3cda767db937fd5e7b8dd73610..f0f6b0e6dc1559dec0dc436a359f5231f6e025aa 100644 --- a/bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js +++ b/bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js @@ -12,22 +12,36 @@ return storage[method_name].apply(storage, argument_list) .push(undefined, function (error) { if ((error.target !== undefined) && (error.target.status === 401)) { + var regexp, + site, + auth_page; if (gadget.state_parameter_dict.jio_storage_name === "ERP5") { - return gadget.redirect({ page: "login" }); + regexp = /^X-Delegate uri=\"(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)\"$/; + auth_page = error.target.getResponseHeader('WWW-Authenticate'); + if (regexp.test(auth_page)) { + site = UriTemplate.parse( + regexp.exec(auth_page)[1] + ).expand({ + came_from: window.location.href, + cors_origin: window.location.origin, + }); + } } if (gadget.state_parameter_dict.jio_storage_name === "DAV") { - var regexp = /^Nayookie login_url=(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)$/, - auth_page = error.target.getResponseHeader('WWW-Authenticate'), - site; + regexp = /^Nayookie login_url=(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)$/; + auth_page = error.target.getResponseHeader('WWW-Authenticate'); if (regexp.test(auth_page)) { site = UriTemplate.parse( regexp.exec(auth_page)[1] - ).expand({back_url: window.location.href, - origin: window.location.protocol + '//' + - window.location.host}); - return gadget.redirect({ toExternal: true, url: site}); + ).expand({ + back_url: window.location.href, + origin: window.location.origin, + }); } } + if (site) { + return gadget.redirect({ toExternal: true, url: site}); + } } throw error; });