github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/docs/assets/js/oauth2-redirect.html (about) 1 <!doctype html> 2 <html lang="en-US"> 3 <title>Swagger UI: OAuth2 Redirect</title> 4 <body onload="run()"> 5 </body> 6 </html> 7 <script> 8 'use strict'; 9 function run () { 10 var oauth2 = window.opener.swaggerUIRedirectOauth2; 11 var sentState = oauth2.state; 12 var redirectUrl = oauth2.redirectUrl; 13 var isValid, qp, arr; 14 15 if (/code|token|error/.test(window.location.hash)) { 16 qp = window.location.hash.substring(1); 17 } else { 18 qp = location.search.substring(1); 19 } 20 21 arr = qp.split("&") 22 arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';}) 23 qp = qp ? JSON.parse('{' + arr.join() + '}', 24 function (key, value) { 25 return key === "" ? value : decodeURIComponent(value) 26 } 27 ) : {} 28 29 isValid = qp.state === sentState 30 31 if (( 32 oauth2.auth.schema.get("flow") === "accessCode"|| 33 oauth2.auth.schema.get("flow") === "authorizationCode" 34 ) && !oauth2.auth.code) { 35 if (!isValid) { 36 oauth2.errCb({ 37 authId: oauth2.auth.name, 38 source: "auth", 39 level: "warning", 40 message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server" 41 }); 42 } 43 44 if (qp.code) { 45 delete oauth2.state; 46 oauth2.auth.code = qp.code; 47 oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl}); 48 } else { 49 let oauthErrorMsg 50 if (qp.error) { 51 oauthErrorMsg = "["+qp.error+"]: " + 52 (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") + 53 (qp.error_uri ? "More info: "+qp.error_uri : ""); 54 } 55 56 oauth2.errCb({ 57 authId: oauth2.auth.name, 58 source: "auth", 59 level: "error", 60 message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server" 61 }); 62 } 63 } else { 64 oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl}); 65 } 66 window.close(); 67 } 68 </script>