github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/api/swagger-ui/oauth2-redirect.html (about) 1 <!-- 2 ~ This file is part of the Smart Home 3 ~ Program complex distribution https://github.com/e154/smart-home 4 ~ Copyright (C) 2023, Filippov Alex 5 ~ 6 ~ This library is free software: you can redistribute it and/or 7 ~ modify it under the terms of the GNU Lesser General Public 8 ~ License as published by the Free Software Foundation; either 9 ~ version 3 of the License, or (at your option) any later version. 10 ~ 11 ~ This library is distributed in the hope that it will be useful, 12 ~ but WITHOUT ANY WARRANTY; without even the implied warranty of 13 ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 ~ Library General Public License for more details. 15 ~ 16 ~ You should have received a copy of the GNU Lesser General Public 17 ~ License along with this library. If not, see 18 ~ <https://www.gnu.org/licenses/>. 19 --> 20 21 <!doctype html> 22 <html lang="en-US"> 23 <head> 24 <title>Swagger UI: OAuth2 Redirect</title> 25 </head> 26 <body> 27 <script> 28 'use strict'; 29 function run () { 30 var oauth2 = window.opener.swaggerUIRedirectOauth2; 31 var sentState = oauth2.state; 32 var redirectUrl = oauth2.redirectUrl; 33 var isValid, qp, arr; 34 35 if (/code|token|error/.test(window.location.hash)) { 36 qp = window.location.hash.substring(1); 37 } else { 38 qp = location.search.substring(1); 39 } 40 41 arr = qp.split("&"); 42 arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';}); 43 qp = qp ? JSON.parse('{' + arr.join() + '}', 44 function (key, value) { 45 return key === "" ? value : decodeURIComponent(value); 46 } 47 ) : {}; 48 49 isValid = qp.state === sentState; 50 51 if (( 52 oauth2.auth.schema.get("flow") === "accessCode" || 53 oauth2.auth.schema.get("flow") === "authorizationCode" || 54 oauth2.auth.schema.get("flow") === "authorization_code" 55 ) && !oauth2.auth.code) { 56 if (!isValid) { 57 oauth2.errCb({ 58 authId: oauth2.auth.name, 59 source: "auth", 60 level: "warning", 61 message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server" 62 }); 63 } 64 65 if (qp.code) { 66 delete oauth2.state; 67 oauth2.auth.code = qp.code; 68 oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl}); 69 } else { 70 let oauthErrorMsg; 71 if (qp.error) { 72 oauthErrorMsg = "["+qp.error+"]: " + 73 (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") + 74 (qp.error_uri ? "More info: "+qp.error_uri : ""); 75 } 76 77 oauth2.errCb({ 78 authId: oauth2.auth.name, 79 source: "auth", 80 level: "error", 81 message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server" 82 }); 83 } 84 } else { 85 oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl}); 86 } 87 window.close(); 88 } 89 90 window.addEventListener('DOMContentLoaded', function () { 91 run(); 92 }); 93 </script> 94 </body> 95 </html>