github.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <form action="/_api/admin/security/passport-github" method="post" class="form-horizontal passportStrategy" id="githubSetting" role="form">
  2. <legend class="alert-anchor">{{ t("security_setting.OAuth.GitHub.name") }} {{ t("security_setting.configuration") }}</legend>
  3. {% set nameForIsGitHubEnabled = "settingForm[security:passport-github:isEnabled]" %}
  4. {% set isGitHubEnabled = settingForm['security:passport-github:isEnabled'] %}
  5. {% set siteUrl = getConfig('crowi', 'app:siteUrl') || '[INVALID]' %}
  6. {% set callbackUrl = siteUrl + '/passport/github/callback' %}
  7. <div class="form-group">
  8. <label for="{{nameForIsGitHubEnabled}}" class="col-xs-3 control-label">{{ t("security_setting.OAuth.GitHub.name") }}</label>
  9. <div class="col-xs-6">
  10. <div class="btn-group btn-toggle" data-toggle="buttons">
  11. <label class="btn btn-default btn-rounded btn-outline {% if isGitHubEnabled %}active{% endif %}" data-active-class="primary">
  12. <input name="{{nameForIsGitHubEnabled}}" value="true" type="radio"
  13. {% if true === isGitHubEnabled %}checked{% endif %}> ON
  14. </label>
  15. <label class="btn btn-default btn-rounded btn-outline {% if !isGitHubEnabled %}active{% endif %}" data-active-class="default">
  16. <input name="{{nameForIsGitHubEnabled}}" value="false" type="radio"
  17. {% if !isGitHubEnabled %}checked{% endif %}> OFF
  18. </label>
  19. </div>
  20. </div>
  21. </div>
  22. <fieldset id="passport-github-hide-when-disabled" {%if !isGitHubEnabled %}style="display: none;"{% endif %}>
  23. <div class="form-group">
  24. <label for="settingForm[security:passport-github:clientId]" class="col-xs-3 control-label">{{ t("security_setting.clientID") }}</label>
  25. <div class="col-xs-6">
  26. <input class="form-control" type="text" name="settingForm[security:passport-github:clientId]" value="{{ settingForm['security:passport-github:clientId'] || '' }}">
  27. <p class="help-block">
  28. <small>
  29. {{ t("security_setting.Use env var if empty", "OAUTH_GITHUB_CLIENT_SECRET") }}
  30. </small>
  31. </p>
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label for="settingForm[security:passport-github:clientSecret]" class="col-xs-3 control-label">{{ t("security_setting.client_secret") }}</label>
  36. <div class="col-xs-6">
  37. <input class="form-control" type="text" name="settingForm[security:passport-github:clientSecret]" value="{{ settingForm['security:passport-github:clientSecret'] || '' }}">
  38. <p class="help-block">
  39. <small>
  40. {{ t("security_setting.Use env var if empty", "OAUTH_GITHUB_CLIENT_SECRET") }}
  41. </small>
  42. </p>
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-xs-3 control-label">{{ t("security_setting.callback_URL") }}</label>
  47. <div class="col-xs-6">
  48. <input class="form-control" type="text" value="{{ callbackUrl }}" readonly>
  49. <p class="help-block small">{{ t("security_setting.desc_of_callback_URL", 'OAuth') }}</p>
  50. {% if !getConfig('crowi', 'app:siteUrl') %}
  51. <div class="alert alert-danger">
  52. <i class="icon-exclamation"></i> {{ t("security_setting.alert_siteUrl_is_not_set", '<a href="/admin/app">' + t('App settings') + '<i class="icon-login"></i></a>') }}
  53. </div>
  54. {% endif %}
  55. </div>
  56. </div>
  57. <div class="form-group">
  58. <div class="col-xs-6 col-xs-offset-3">
  59. <div class="checkbox checkbox-info">
  60. <input type="checkbox" id="bindByUserName-GitHub" name="settingForm[security:passport-github:isSameUsernameTreatedAsIdenticalUser]" value="1"
  61. {% if settingForm['security:passport-github:isSameUsernameTreatedAsIdenticalUser'] %}checked{% endif %} />
  62. <label for="bindByUserName-GitHub">
  63. {{ t("security_setting.Treat username matching as identical", "username") }}
  64. </label>
  65. <p class="help-block">
  66. <small>
  67. {{ t("security_setting.Treat username matching as identical_warn", "username") }}
  68. </small>
  69. </p>
  70. </div>
  71. </div>
  72. </div>
  73. </fieldset>
  74. <div class="form-group" id="btn-update">
  75. <div class="col-xs-offset-3 col-xs-6">
  76. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  77. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  78. </div>
  79. </div>
  80. </form>
  81. {# Help Section #}
  82. <hr>
  83. <div style="min-height: 300px;">
  84. <h4>
  85. <i class="icon-question" aria-hidden="true"></i>
  86. <a href="#collapseHelpForGithubOauth" data-toggle="collapse">{{ t("security_setting.OAuth.how_to.github") }}</a>
  87. </h4>
  88. <ol id="collapseHelpForGithubOauth" class="collapse">
  89. <li>{{ t("security_setting.OAuth.GitHub.register_1", "https://github.com/settings/developers", "GitHub Developer Settings") }}</li>
  90. <li>{{ t("security_setting.OAuth.GitHub.register_2", callbackUrl) }}</li>
  91. <li>{{ t("security_setting.OAuth.GitHub.register_3") }}</li>
  92. </ol>
  93. </div>
  94. <script>
  95. $('input[name="settingForm[security:passport-github:isEnabled]"]').change(function() {
  96. const isEnabled = ($(this).val() === "true");
  97. if (isEnabled) {
  98. $('#passport-github-hide-when-disabled').show(400);
  99. }
  100. else {
  101. $('#passport-github-hide-when-disabled').hide(400);
  102. }
  103. });
  104. </script>