|
13 | 13 | '/project', '/component', '/vulnerability', '/license', '/login', '/change-password' |
14 | 14 | ]; |
15 | 15 | function getContextPath() { |
16 | | - if (window.location.pathname === '/static/oidc-callback.html') { |
17 | | - // App is deployed in the root context. Return an empty string. |
18 | | - return ""; |
19 | | - } else { |
20 | | - // App is deployed in a non-root context. Return the context. |
21 | | - return window.location.pathname.substring(0, window.location.pathname.indexOf("/",2)); |
22 | | - } |
| 16 | + if (window.location.pathname === '/static/oidc-callback.html') { |
| 17 | + // App is deployed in the root context. Return an empty string. |
| 18 | + return ""; |
| 19 | + } else { |
| 20 | + // App is deployed in a non-root context. Return the context. |
| 21 | + return window.location.pathname.substring(0, window.location.pathname.indexOf("/",2)); |
| 22 | + } |
23 | 23 | } |
24 | 24 | function isUrlSaveForRedirect(redirectUrl) { |
25 | | - const contextRoot = getContextPath(); |
26 | | - try { |
27 | | - const resultingUrl = new URL(redirectUrl, window.location.origin); |
28 | | - return resultingUrl.origin === window.location.origin |
| 25 | + const contextRoot = getContextPath(); |
| 26 | + try { |
| 27 | + const resultingUrl = new URL(redirectUrl, window.location.origin); |
| 28 | + return resultingUrl.origin === window.location.origin |
29 | 29 | && /^https?:$/.test(resultingUrl.protocol) |
30 | 30 | && acceptableRootContextPaths.map(r => contextRoot + r).some(p => redirectUrl.startsWith(p)); |
31 | | - } catch(invalidUrl) { |
32 | | - return false; |
33 | | - } |
| 31 | + } catch(invalidUrl) { |
| 32 | + return false; |
| 33 | + } |
34 | 34 | } |
35 | 35 |
|
36 | 36 | axios.get("/static/config.json") |
|
44 | 44 | }); |
45 | 45 | }) |
46 | 46 | .then((oidcUserManager) => { |
47 | | - const redirectTo = (new URLSearchParams(window.location.search)).get("redirect"); |
48 | | - |
49 | | - oidcUserManager.getUser() |
50 | | - .then((user) => { |
51 | | - if (user !== null) { |
52 | | - // Implicit flow: Token is already present in URL |
53 | | - window.location.href = redirectTo && isUrlSaveForRedirect(redirectTo) ? redirectTo : "../"; |
54 | | - return Promise.resolve() |
55 | | - } else { |
56 | | - // Code flow: Token must be acquired in exchange for auth code |
57 | | - return oidcUserManager.signinRedirectCallback(); |
58 | | - } |
59 | | - }) |
60 | | - .then((user) => { |
61 | | - window.location.href = redirectTo && isUrlSaveForRedirect(redirectTo) ? redirectTo : "../"; |
62 | | - }) |
63 | | - .catch((err) => { |
64 | | - console.log(err); |
65 | | - }) |
| 47 | + return oidcUserManager.signinRedirectCallback(); |
| 48 | + }) |
| 49 | + .then((user) => { |
| 50 | + const redirectTo = user.state; |
| 51 | + window.location.href = redirectTo && isUrlSaveForRedirect(redirectTo) ? redirectTo : "../"; |
66 | 52 | }) |
67 | 53 | .catch((err) => { |
68 | 54 | console.log(err); |
|
0 commit comments