admin-auth.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img(src='/svg/icon-unlock.svg', alt='Authentication', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text Authentication
  9. .subheading.grey--text Configure the authentication settings of your wiki
  10. v-spacer
  11. v-btn(outline, color='grey', @click='refresh', large)
  12. v-icon refresh
  13. v-btn(color='primary', @click='save', depressed, large)
  14. v-icon(left) chevron_right
  15. span Apply Configuration
  16. v-card.mt-3
  17. v-tabs(color='grey darken-2', fixed-tabs, slider-color='white', show-arrows, dark)
  18. v-tab(key='settings'): v-icon settings
  19. v-tab(v-for='strategy in activeStrategies', :key='strategy.key') {{ strategy.title }}
  20. v-tab-item(key='settings', :transition='false', :reverse-transition='false')
  21. v-container.pa-3(fluid, grid-list-md)
  22. v-layout(row, wrap)
  23. v-flex(xs12, md6)
  24. .body-2.grey--text.text--darken-1 Select which authentication strategies to enable:
  25. .caption.grey--text.pb-2 Some strategies require additional configuration in their dedicated tab (when selected).
  26. v-form
  27. v-checkbox.my-0(
  28. v-for='strategy in strategies'
  29. v-model='strategy.isEnabled'
  30. :key='strategy.key'
  31. :label='strategy.title'
  32. color='primary'
  33. :disabled='strategy.key === `local`'
  34. hide-details
  35. )
  36. v-flex(xs12, md6)
  37. .pa-3.grey.radius-7(:class='$vuetify.dark ? "darken-4" : "lighten-5"')
  38. .body-2.grey--text.text--darken-1 Advanced Settings
  39. v-text-field.mt-3.md2(
  40. v-model='jwtAudience'
  41. outline
  42. background-color='grey lighten-2'
  43. prepend-icon='account_balance'
  44. label='JWT Audience'
  45. hint='Audience URN used in JWT issued upon login. Usually your domain name. (e.g. urn:your.domain.com)'
  46. persistent-hint
  47. )
  48. v-text-field.mt-3.md2(
  49. v-model='jwtExpiration'
  50. outline
  51. background-color='grey lighten-2'
  52. prepend-icon='schedule'
  53. label='Token Expiration'
  54. hint='The expiration period of a token until it must be renewed. (default: 30m)'
  55. persistent-hint
  56. )
  57. v-text-field.mt-3.md2(
  58. v-model='jwtRenewablePeriod'
  59. outline
  60. background-color='grey lighten-2'
  61. prepend-icon='update'
  62. label='Token Renewal Period'
  63. hint='The maximum period a token can be renewed when expired. (default: 14d)'
  64. persistent-hint
  65. )
  66. v-tab-item(v-for='(strategy, n) in activeStrategies', :key='strategy.key', :transition='false', :reverse-transition='false')
  67. v-card.wiki-form.pa-3(flat, tile)
  68. v-form
  69. .authlogo
  70. img(:src='strategy.logo', :alt='strategy.title')
  71. v-subheader.pl-0 {{strategy.title}}
  72. .caption {{strategy.description}}
  73. .caption: a(:href='strategy.website') {{strategy.website}}
  74. v-divider.mt-3
  75. v-subheader.pl-0 Strategy Configuration
  76. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1') This strategy has no configuration options you can modify.
  77. template(v-else, v-for='cfg in strategy.config')
  78. v-select(
  79. v-if='cfg.value.type === "string" && cfg.value.enum'
  80. outline
  81. background-color='grey lighten-2'
  82. :items='cfg.value.enum'
  83. :key='cfg.key'
  84. :label='cfg.value.title'
  85. v-model='cfg.value.value'
  86. prepend-icon='settings_applications'
  87. :hint='cfg.value.hint ? cfg.value.hint : ""'
  88. persistent-hint
  89. :class='cfg.value.hint ? "mb-2" : ""'
  90. )
  91. v-switch.mb-3(
  92. v-else-if='cfg.value.type === "boolean"'
  93. :key='cfg.key'
  94. :label='cfg.value.title'
  95. v-model='cfg.value.value'
  96. color='primary'
  97. prepend-icon='settings_applications'
  98. :hint='cfg.value.hint ? cfg.value.hint : ""'
  99. persistent-hint
  100. )
  101. v-text-field(
  102. v-else
  103. outline
  104. background-color='grey lighten-2'
  105. :key='cfg.key'
  106. :label='cfg.value.title'
  107. v-model='cfg.value.value'
  108. prepend-icon='settings_applications'
  109. :hint='cfg.value.hint ? cfg.value.hint : ""'
  110. persistent-hint
  111. :class='cfg.value.hint ? "mb-2" : ""'
  112. )
  113. v-divider.mt-3
  114. v-subheader.pl-0 Registration
  115. .pr-3
  116. v-switch.ml-3(
  117. v-model='strategy.selfRegistration'
  118. label='Allow self-registration'
  119. color='primary'
  120. hint='Allow any user successfully authorized by the strategy to access the wiki.'
  121. persistent-hint
  122. )
  123. v-combobox.ml-3.mt-3(
  124. label='Limit to specific email domains'
  125. v-model='strategy.domainWhitelist'
  126. prepend-icon='mail_outline'
  127. outline
  128. background-color='grey lighten-2'
  129. persistent-hint
  130. small-chips
  131. deletable-chips
  132. clearable
  133. multiple
  134. chips
  135. )
  136. v-autocomplete.ml-3(
  137. outline
  138. background-color='grey lighten-2'
  139. :items='groups'
  140. item-text='name'
  141. item-value='id'
  142. label='Assign to group'
  143. v-model='strategy.autoEnrollGroups'
  144. prepend-icon='people'
  145. hint='Automatically assign new users to these groups.'
  146. small-chips
  147. persistent-hint
  148. deletable-chips
  149. clearable
  150. multiple
  151. chips
  152. )
  153. template(v-if='strategy.key === `local`')
  154. v-divider.mt-3
  155. v-subheader.pl-0 Security
  156. .pr-3
  157. v-switch.ml-3(
  158. :disabled='true'
  159. v-model='strategy.recaptcha'
  160. label='Use reCAPTCHA by Google'
  161. color='primary'
  162. hint='Protects against spam robots and malicious registrations.'
  163. persistent-hint
  164. )
  165. </template>
  166. <script>
  167. import _ from 'lodash'
  168. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  169. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  170. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  171. export default {
  172. filters: {
  173. startCase(val) { return _.startCase(val) }
  174. },
  175. data() {
  176. return {
  177. groups: [],
  178. strategies: [],
  179. jwtAudience: 'urn:wiki.js',
  180. jwtExpiration: '30m',
  181. jwtRenewablePeriod: '14d'
  182. }
  183. },
  184. computed: {
  185. activeStrategies() {
  186. return _.filter(this.strategies, 'isEnabled')
  187. }
  188. },
  189. methods: {
  190. async refresh() {
  191. await this.$apollo.queries.strategies.refetch()
  192. this.$store.commit('showNotification', {
  193. message: 'List of strategies has been refreshed.',
  194. style: 'success',
  195. icon: 'cached'
  196. })
  197. },
  198. async save() {
  199. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  200. await this.$apollo.mutate({
  201. mutation: strategiesSaveMutation,
  202. variables: {
  203. strategies: this.strategies.map(str => _.pick(str, [
  204. 'isEnabled',
  205. 'key',
  206. 'config',
  207. 'selfRegistration',
  208. 'domainWhitelist',
  209. 'autoEnrollGroups'
  210. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  211. }
  212. })
  213. this.$store.commit('showNotification', {
  214. message: 'Authentication configuration saved successfully.',
  215. style: 'success',
  216. icon: 'check'
  217. })
  218. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  219. }
  220. },
  221. apollo: {
  222. strategies: {
  223. query: strategiesQuery,
  224. fetchPolicy: 'network-only',
  225. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  226. watchLoading (isLoading) {
  227. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  228. }
  229. },
  230. groups: {
  231. query: groupsQuery,
  232. fetchPolicy: 'network-only',
  233. update: (data) => data.groups.list,
  234. watchLoading (isLoading) {
  235. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  236. }
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang='scss' scoped>
  242. .authlogo {
  243. width: 250px;
  244. height: 85px;
  245. float:right;
  246. display: flex;
  247. justify-content: flex-end;
  248. align-items: center;
  249. img {
  250. max-width: 100%;
  251. max-height: 50px;
  252. }
  253. }
  254. </style>