25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.4 KiB

  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. if (/code|token|error/.test(window.location.hash)) {
  15. qp = window.location.hash.substring(1);
  16. } else {
  17. qp = location.search.substring(1);
  18. }
  19. arr = qp.split("&")
  20. arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
  21. qp = qp ? JSON.parse('{' + arr.join() + '}',
  22. function (key, value) {
  23. return key === "" ? value : decodeURIComponent(value)
  24. }
  25. ) : {}
  26. isValid = qp.state === sentState
  27. if ((
  28. oauth2.auth.schema.get("flow") === "accessCode"||
  29. oauth2.auth.schema.get("flow") === "authorizationCode"
  30. ) && !oauth2.auth.code) {
  31. if (!isValid) {
  32. oauth2.errCb({
  33. authId: oauth2.auth.name,
  34. source: "auth",
  35. level: "warning",
  36. message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
  37. });
  38. }
  39. if (qp.code) {
  40. delete oauth2.state;
  41. oauth2.auth.code = qp.code;
  42. oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
  43. } else {
  44. let oauthErrorMsg
  45. if (qp.error) {
  46. oauthErrorMsg = "["+qp.error+"]: " +
  47. (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
  48. (qp.error_uri ? "More info: "+qp.error_uri : "");
  49. }
  50. oauth2.errCb({
  51. authId: oauth2.auth.name,
  52. source: "auth",
  53. level: "error",
  54. message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
  55. });
  56. }
  57. } else {
  58. oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
  59. }
  60. window.close();
  61. }
  62. </script>