oauth.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. <label>Select OAuth IdP (aka Service provider)</label>
  79. <div class="ui selection fluid dropdown" autocomplete="false">
  80. <input type="hidden" id="idp" name="idp" autocomplete="false">
  81. <i class="dropdown icon"></i>
  82. <div class="default text">Select service provider</div>
  83. <div id="idplist" class="menu">
  84. </div>
  85. </div>
  86. </div>
  87. <div class="field">
  88. <label>Redirect URL (you have to provide <span id="redirectspan">https://YOUR_DOMAIN/system/auth/oauth/authorize</span> at the 3rd auth rely)</label>
  89. <div class="ui fluid input">
  90. <input type="text" id="redirecturl" placeholder="https://YOUR_DOMAIN/">
  91. </div>
  92. </div>
  93. <div class="field" id="server" style="display: none;">
  94. <label>Server URL</label>
  95. <div class="ui fluid input">
  96. <input type="text" id="serverurl" placeholder="http://YOUR_DOMAIN/">
  97. </div>
  98. </div>
  99. <div class="field">
  100. <label>Client ID</label>
  101. <div class="ui fluid input">
  102. <input type="text" id="clientid" placeholder="Client ID">
  103. </div>
  104. </div>
  105. <div class="field">
  106. <label>Client Secret</label>
  107. <div class="ui fluid input">
  108. <input type="text" id="clientsecret" placeholder="Client Secret">
  109. </div>
  110. </div>
  111. <button id="ntb" onclick="update();" class="ui green button" type="submit">Update</button>
  112. </div>
  113. <div class="ui divider"></div>
  114. <br><br>
  115. </div>
  116. <script>
  117. $(document).ready(function() {
  118. loadIdpList();
  119. read();
  120. initPlaceholder();
  121. });
  122. $("#idp").change(function() {
  123. if ($("#idp").val() == "Gitlab") {
  124. $("#server").removeAttr("style");
  125. } else {
  126. $("#server").attr("style", "display:none;");
  127. }
  128. });
  129. $("#redirecturl").on('input propertychange', function() {
  130. if ($("#redirecturl").val() == "") {
  131. $("#redirectspan").text(window.location.origin + "/system/auth/oauth/authorize");
  132. } else {
  133. $("#redirectspan").text($("#redirecturl").val() + "/system/auth/oauth/authorize");
  134. }
  135. });
  136. function read() {
  137. $.getJSON("../../system/auth/oauth/config/read", function(data) {
  138. if (data.enabled) {
  139. $("#enable").parent().checkbox("check")
  140. }
  141. $("#idp").parent().dropdown("set selected", data.idp);
  142. $("#serverurl").val(data.server_url);
  143. $("#redirecturl").val(data.redirect_url);
  144. $("#clientid").val(data.client_id);
  145. $("#clientsecret").val(data.client_secret);
  146. });
  147. }
  148. function update() {
  149. $.post("../../system/auth/oauth/config/write", {
  150. enabled: $("#enable").parent().checkbox("is checked"),
  151. idp: $("#idp").val(),
  152. redirecturl: $("#redirecturl").val(),
  153. clientid: $("#clientid").val(),
  154. clientsecret: $("#clientsecret").val(),
  155. serverurl: $("#serverurl").val()
  156. })
  157. .done(function(data) {
  158. if (data.error != undefined) {
  159. alert(data.error);
  160. } else {
  161. //OK!
  162. $("#updateSet").stop().finish().slideDown("fast").delay(3000).slideUp('fast');
  163. }
  164. });
  165. }
  166. function loadIdpList() {
  167. $("#idplist").html("");
  168. var data = ["Google", "Microsoft", "Github", "Gitlab"];
  169. if (data.error !== undefined) {
  170. alert(data.error);
  171. } else {
  172. for (var i = 0; i < data.length; i++) {
  173. let idpinfo = data[i];
  174. $("#idplist").append(`<div class="item" data-value="${idpinfo}">${idpinfo}</div>`);
  175. }
  176. }
  177. $("#idplist").parent().dropdown();
  178. }
  179. function initPlaceholder() {
  180. $("#redirectspan").text(window.location.origin + "/system/auth/oauth/authorize");
  181. $("#redirecturl").attr("placeholder", window.location.origin);
  182. $("#serverurl").attr("placeholder", "https://gitlab.com");
  183. }
  184. </script>
  185. </body>
  186. </html>