oauth.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <html>
  2. <head>
  3. <title>OAuth Login</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.css">
  7. <script type="application/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="application/javascript" src="../../script/clipboard.min.js"></script>
  9. <script type="application/javascript" src="../../script/semantic/semantic.js"></script>
  10. <style>
  11. /* Tooltip container */
  12. .tooltip {
  13. position: relative;
  14. display: inline-block;
  15. border-bottom: 1px dotted black;
  16. /* If you want dots under the hoverable text */
  17. }
  18. /* Tooltip text */
  19. .tooltip .tooltiptext {
  20. visibility: hidden;
  21. width: 120px;
  22. background-color: #555;
  23. color: #fff;
  24. text-align: center;
  25. padding: 5px 0;
  26. border-radius: 6px;
  27. /* Position the tooltip text */
  28. position: absolute;
  29. z-index: 1;
  30. bottom: 125%;
  31. left: 50%;
  32. margin-left: -60px;
  33. /* Fade in tooltip */
  34. opacity: 0;
  35. transition: opacity 0.3s;
  36. }
  37. /* Tooltip arrow */
  38. .tooltip .tooltiptext::after {
  39. content: "";
  40. position: absolute;
  41. top: 100%;
  42. left: 50%;
  43. margin-left: -5px;
  44. border-width: 5px;
  45. border-style: solid;
  46. border-color: #555 transparent transparent transparent;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="ui container">
  52. <div class="ui basic segment">
  53. <div class="ui header">
  54. <i class="key icon"></i>
  55. <div class="content">
  56. OAuth Access
  57. <div class="sub header">Allow external account to access ArozOS with OAuth 2.0</div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="ui divider"></div>
  62. <div class="ui green inverted segment" style="display:none;" id="updateSet">
  63. <h5 class="ui header">
  64. <i class="checkmark icon"></i>
  65. <div class="content">
  66. Setting Updated
  67. </div>
  68. </h5>
  69. </div>
  70. <div class="ui form">
  71. <div class="field">
  72. <div class="ui toggle checkbox">
  73. <input type="checkbox" id="enable" name="public">
  74. <label>Enable OAuth</label>
  75. </div>
  76. </div>
  77. <div class="field">
  78. <div class="ui toggle checkbox">
  79. <input type="checkbox" id="autoredirect" name="autoredirect">
  80. <label>Auto redirect</label>
  81. </div>
  82. </div>
  83. <div class="field">
  84. <label>Select OAuth IdP (aka Service provider)</label>
  85. <div class="ui selection fluid dropdown" autocomplete="false">
  86. <input type="hidden" id="idp" name="idp" autocomplete="false">
  87. <i class="dropdown icon"></i>
  88. <div class="default text">Select service provider</div>
  89. <div id="idplist" class="menu">
  90. </div>
  91. </div>
  92. </div>
  93. <div class="field">
  94. <label>Redirect URL (you have to provide <span id="redirectspan">https://YOUR_DOMAIN/system/auth/oauth/authorize</span> at the 3rd auth rely)</label>
  95. <div class="ui fluid input">
  96. <input type="text" id="redirecturl" placeholder="https://YOUR_DOMAIN/">
  97. </div>
  98. </div>
  99. <div class="field" id="server" style="display: none;">
  100. <label>Server URL</label>
  101. <div class="ui fluid input">
  102. <input type="text" id="serverurl" placeholder="http://YOUR_DOMAIN/">
  103. </div>
  104. </div>
  105. <div class="field">
  106. <label>Client ID</label>
  107. <div class="ui fluid input">
  108. <input type="text" id="clientid" placeholder="Client ID">
  109. </div>
  110. </div>
  111. <div class="field">
  112. <label>Client Secret</label>
  113. <div class="ui fluid input">
  114. <input type="text" id="clientsecret" placeholder="Client Secret">
  115. </div>
  116. </div>
  117. <button id="ntb" onclick="update();" class="ui green button" type="submit">Update</button>
  118. </div>
  119. <div class="ui divider"></div>
  120. <br><br>
  121. </div>
  122. <script>
  123. $(document).ready(function() {
  124. loadIdpList();
  125. read();
  126. initPlaceholder();
  127. });
  128. $("#idp").change(function() {
  129. if ($("#idp").val() == "Gitlab") {
  130. $("#server").removeAttr("style");
  131. } else {
  132. $("#server").attr("style", "display:none;");
  133. }
  134. });
  135. $("#redirecturl").on('input propertychange', function() {
  136. if ($("#redirecturl").val() == "") {
  137. $("#redirectspan").text(window.location.origin + "/system/auth/oauth/authorize");
  138. } else {
  139. $("#redirectspan").text($("#redirecturl").val() + "/system/auth/oauth/authorize");
  140. }
  141. });
  142. function read() {
  143. $.getJSON("../../system/auth/oauth/config/read", function(data) {
  144. if (data.enabled) {
  145. $("#enable").parent().checkbox("check")
  146. }
  147. if (data.autoredirect) {
  148. $("#autoredirect").parent().checkbox("check")
  149. }
  150. $("#idp").parent().dropdown("set selected", data.idp);
  151. $("#serverurl").val(data.server_url);
  152. $("#redirecturl").val(data.redirect_url);
  153. $("#clientid").val(data.client_id);
  154. $("#clientsecret").val(data.client_secret);
  155. });
  156. }
  157. function update() {
  158. $.post("../../system/auth/oauth/config/write", {
  159. enabled: $("#enable").parent().checkbox("is checked"),
  160. autoredirect: $("#autoredirect").parent().checkbox("is checked"),
  161. idp: $("#idp").val(),
  162. redirecturl: $("#redirecturl").val(),
  163. clientid: $("#clientid").val(),
  164. clientsecret: $("#clientsecret").val(),
  165. serverurl: $("#serverurl").val()
  166. })
  167. .done(function(data) {
  168. if (data.error != undefined) {
  169. alert(data.error);
  170. } else {
  171. //OK!
  172. $("#updateSet").stop().finish().slideDown("fast").delay(3000).slideUp('fast');
  173. }
  174. });
  175. }
  176. function loadIdpList() {
  177. $("#idplist").html("");
  178. var data = ["Google", "Microsoft", "Github", "Gitlab"];
  179. if (data.error !== undefined) {
  180. alert(data.error);
  181. } else {
  182. for (var i = 0; i < data.length; i++) {
  183. let idpinfo = data[i];
  184. $("#idplist").append(`<div class="item" data-value="${idpinfo}">${idpinfo}</div>`);
  185. }
  186. }
  187. $("#idplist").parent().dropdown();
  188. }
  189. function initPlaceholder() {
  190. $("#redirectspan").text(window.location.origin + "/system/auth/oauth/authorize");
  191. $("#redirecturl").attr("placeholder", window.location.origin);
  192. $("#serverurl").attr("placeholder", "https://gitlab.com");
  193. }
  194. </script>
  195. </body>
  196. </html>