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.

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