You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
2.5 KiB

  1. <!doctype html>
  2. <html lang="en-US">
  3. <head>
  4. <title>Swagger UI: OAuth2 Redirect</title>
  5. </head>
  6. <body>
  7. </body>
  8. </html>
  9. <script>
  10. 'use strict';
  11. function run () {
  12. var oauth2 = window.opener.swaggerUIRedirectOauth2;
  13. var sentState = oauth2.state;
  14. var redirectUrl = oauth2.redirectUrl;
  15. var isValid, qp, arr;
  16. if (/code|token|error/.test(window.location.hash)) {
  17. qp = window.location.hash.substring(1);
  18. } else {
  19. qp = location.search.substring(1);
  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. isValid = qp.state === sentState
  29. if ((
  30. oauth2.auth.schema.get("flow") === "accessCode"||
  31. oauth2.auth.schema.get("flow") === "authorizationCode"
  32. ) && !oauth2.auth.code) {
  33. if (!isValid) {
  34. oauth2.errCb({
  35. authId: oauth2.auth.name,
  36. source: "auth",
  37. level: "warning",
  38. message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
  39. });
  40. }
  41. if (qp.code) {
  42. delete oauth2.state;
  43. oauth2.auth.code = qp.code;
  44. oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
  45. } else {
  46. let oauthErrorMsg
  47. if (qp.error) {
  48. oauthErrorMsg = "["+qp.error+"]: " +
  49. (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
  50. (qp.error_uri ? "More info: "+qp.error_uri : "");
  51. }
  52. oauth2.errCb({
  53. authId: oauth2.auth.name,
  54. source: "auth",
  55. level: "error",
  56. message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
  57. });
  58. }
  59. } else {
  60. oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
  61. }
  62. window.close();
  63. }
  64. window.addEventListener('DOMContentLoaded', function () {
  65. run();
  66. });
  67. </script>