oauth.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en" data-theme="light">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="referrer" content="no-referrer">
  7. <title>Mail sign-in</title>
  8. <link rel="icon" href="img/icon.svg">
  9. <link rel="stylesheet" href="../script/semantic/components/icon.min.css">
  10. <link rel="stylesheet" href="style/mail.css">
  11. <script src="../script/jquery.min.js"></script>
  12. <script src="../script/ao_module.js"></script>
  13. <style>
  14. body { display: flex; align-items: center; justify-content: center; height: 100%; overflow: auto; }
  15. .card { max-width: 420px; margin: 20px; padding: 32px 28px; text-align: center; background: var(--surface); border-radius: 16px; border: 1px solid var(--border-strong); }
  16. .card img { width: 56px; height: 56px; }
  17. .card h1 { font-size: 19px; margin: 16px 0 8px; }
  18. .card p { color: var(--text-2); line-height: 1.55; margin: 0 0 16px; }
  19. .card .spinner { margin: 6px auto 0; }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="card">
  24. <img src="img/icon.svg" alt="">
  25. <h1 id="title">Finishing sign-in…</h1>
  26. <p id="message">Please wait while ArozOS Mail completes the connection.</p>
  27. <div class="spinner large" id="spinner"></div>
  28. </div>
  29. <script src="script/util.js"></script>
  30. <script src="script/api.js"></script>
  31. <script>
  32. /*
  33. Mail — OAuth redirect landing page
  34. The provider sends the browser here with ?code=…&state=…. The code
  35. is exchanged on the server (together with the PKCE verifier only the
  36. server knows); this page never sees a token. The account wizard,
  37. waiting in the main window, is told through a BroadcastChannel and
  38. also polls the sign-in status, so it continues even if this window
  39. lost its opener.
  40. */
  41. (function () {
  42. "use strict";
  43. var params = new URLSearchParams(window.location.search);
  44. var state = params.get("state") || "";
  45. var title = document.getElementById("title");
  46. var message = document.getElementById("message");
  47. var spinner = document.getElementById("spinner");
  48. if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
  49. document.documentElement.setAttribute("data-theme", "dark");
  50. }
  51. function notify(ok) {
  52. try {
  53. var channel = new BroadcastChannel("arozos-mail-oauth");
  54. channel.postMessage({ state: state, ok: ok });
  55. channel.close();
  56. } catch (e) { /* the wizard polls as well */ }
  57. }
  58. function done(ok, heading, text) {
  59. spinner.style.display = "none";
  60. title.textContent = heading;
  61. message.textContent = text;
  62. notify(ok);
  63. if (ok) {
  64. setTimeout(function () { window.close(); }, 1500);
  65. }
  66. }
  67. //Remove the code from the address bar and history straight away
  68. var fullAddress = window.location.href;
  69. try {
  70. history.replaceState(null, "", window.location.pathname);
  71. } catch (e) { /* ignore */ }
  72. if (params.get("error")) {
  73. done(false, "Sign-in was not completed", params.get("error_description") || params.get("error"));
  74. return;
  75. }
  76. if (!state || !params.get("code")) {
  77. done(false, "Nothing to do here", "This page finishes a mail sign-in started from the Mail app.");
  78. return;
  79. }
  80. Mail.api.accounts("oauthComplete", { state: state, code: fullAddress }).then(function (status) {
  81. done(true, "You're signed in", (status.email ? status.email + " is connected. " : "") + "You can close this window and return to Mail.");
  82. }).catch(function (error) {
  83. done(false, "Sign-in failed", error.message);
  84. });
  85. })();
  86. </script>
  87. </body>
  88. </html>