|
36 | 36 | </div> |
37 | 37 |
|
38 | 38 | <script> |
| 39 | + function normalizeLoopbackAPIEndpoint(endpoint, currentOrigin) { |
| 40 | + try { |
| 41 | + const endpointURL = new URL(endpoint); |
| 42 | + const originURL = new URL(currentOrigin); |
| 43 | + const isLoopbackHostname = (hostname) => |
| 44 | + hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]' || hostname === '::1'; |
| 45 | + |
| 46 | + const isLoopbackUpgrade = |
| 47 | + endpointURL.protocol === 'http:' && |
| 48 | + originURL.protocol === 'https:' && |
| 49 | + isLoopbackHostname(endpointURL.hostname) && |
| 50 | + isLoopbackHostname(originURL.hostname) && |
| 51 | + endpointURL.hostname === originURL.hostname && |
| 52 | + (endpointURL.port === '' || endpointURL.port === '80') && |
| 53 | + (originURL.port === '' || originURL.port === '443'); |
| 54 | + |
| 55 | + if (isLoopbackUpgrade) { |
| 56 | + return originURL.origin; |
| 57 | + } |
| 58 | + } catch (error) { |
| 59 | + return endpoint; |
| 60 | + } |
| 61 | + |
| 62 | + return endpoint; |
| 63 | + } |
| 64 | + |
| 65 | + const apiEndpoint = normalizeLoopbackAPIEndpoint(localStorage.getItem('api'), location.origin); |
| 66 | + localStorage.setItem('api', apiEndpoint); |
39 | 67 | const baseUrl = localStorage.getItem('provider_url'); |
40 | 68 | const client_id = localStorage.getItem('client_id'); |
41 | 69 | const client_secret = localStorage.getItem('client_secret'); |
|
116 | 144 | "password": "tokens['access_token']", |
117 | 145 | "token": tokens['access_token'], |
118 | 146 | "refresh_token": tokens['refresh_token'], |
119 | | - "endpoint": localStorage.getItem('api'), |
| 147 | + "endpoint": apiEndpoint, |
120 | 148 | "egiSession": users |
121 | 149 | }) |
122 | 150 | localStorage.setItem("authData",authData); |
|
0 commit comments