You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
9.8 KiB

  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. v-icon(size='80', color='grey lighten-2') lock_outline
  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.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. deletable-chips
  131. clearable
  132. multiple
  133. chips
  134. )
  135. v-autocomplete.ml-3(
  136. outline
  137. background-color='grey lighten-2'
  138. :items='groups'
  139. item-text='name'
  140. item-value='id'
  141. label='Assign to group'
  142. v-model='strategy.autoEnrollGroups'
  143. prepend-icon='people'
  144. hint='Automatically assign new users to these groups.'
  145. persistent-hint
  146. deletable-chips
  147. clearable
  148. multiple
  149. chips
  150. )
  151. </template>
  152. <script>
  153. import _ from 'lodash'
  154. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  155. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  156. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  157. export default {
  158. filters: {
  159. startCase(val) { return _.startCase(val) }
  160. },
  161. data() {
  162. return {
  163. groups: [],
  164. strategies: [],
  165. jwtAudience: 'urn:wiki.js',
  166. jwtExpiration: '30m',
  167. jwtRenewablePeriod: '14d'
  168. }
  169. },
  170. computed: {
  171. activeStrategies() {
  172. return _.filter(this.strategies, 'isEnabled')
  173. }
  174. },
  175. methods: {
  176. async refresh() {
  177. await this.$apollo.queries.strategies.refetch()
  178. this.$store.commit('showNotification', {
  179. message: 'List of strategies has been refreshed.',
  180. style: 'success',
  181. icon: 'cached'
  182. })
  183. },
  184. async save() {
  185. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  186. await this.$apollo.mutate({
  187. mutation: strategiesSaveMutation,
  188. variables: {
  189. strategies: this.strategies.map(str => _.pick(str, [
  190. 'isEnabled',
  191. 'key',
  192. 'config',
  193. 'selfRegistration',
  194. 'domainWhitelist',
  195. 'autoEnrollGroups'
  196. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  197. }
  198. })
  199. this.$store.commit('showNotification', {
  200. message: 'Authentication configuration saved successfully.',
  201. style: 'success',
  202. icon: 'check'
  203. })
  204. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  205. }
  206. },
  207. apollo: {
  208. strategies: {
  209. query: strategiesQuery,
  210. fetchPolicy: 'network-only',
  211. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  212. watchLoading (isLoading) {
  213. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  214. }
  215. },
  216. groups: {
  217. query: groupsQuery,
  218. fetchPolicy: 'network-only',
  219. update: (data) => data.groups.list,
  220. watchLoading (isLoading) {
  221. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang='scss' scoped>
  228. .authlogo {
  229. width: 250px;
  230. height: 85px;
  231. float:right;
  232. display: flex;
  233. justify-content: flex-end;
  234. align-items: center;
  235. img {
  236. max-width: 100%;
  237. max-height: 50px;
  238. }
  239. }
  240. </style>