admin-auth.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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.animated.fadeInUp(src='/svg/icon-unlock.svg', alt='Authentication', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:auth.title') }}
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:auth.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', @click='refresh', large)
  12. v-icon refresh
  13. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  14. v-icon(left) check
  15. span {{$t('common:actions.apply')}}
  16. v-flex(lg3, xs12)
  17. v-card.animated.fadeInUp
  18. v-toolbar(flat, color='primary', dark, dense)
  19. .subheading {{$t('admin:auth.strategies')}}
  20. v-list(two-line, dense).py-0
  21. template(v-for='(str, idx) in strategies')
  22. v-list-tile(:key='str.key', @click='selectedStrategy = str.key', :disabled='!str.isAvailable')
  23. v-list-tile-avatar
  24. v-icon(color='grey', v-if='!str.isAvailable') indeterminate_check_box
  25. v-icon(color='primary', v-else-if='str.isEnabled && str.key !== `local`', v-ripple, @click='str.isEnabled = false') check_box
  26. v-icon(color='primary', v-else-if='str.isEnabled && str.key === `local`') check_box
  27. v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') check_box_outline_blank
  28. v-list-tile-content
  29. v-list-tile-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedStrategy === str.key ? `primary--text` : ``)') {{ str.title }}
  30. v-list-tile-sub-title.caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedStrategy === str.key ? `blue--text ` : ``)') {{ str.description }}
  31. v-list-tile-avatar(v-if='selectedStrategy === str.key')
  32. v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
  33. v-divider(v-if='idx < strategies.length - 1')
  34. v-card.wiki-form.mt-3.animated.fadeInUp.wait-p2s
  35. v-toolbar(flat, color='primary', dark, dense)
  36. .subheading {{$t('admin:auth.globalAdvSettings')}}
  37. v-card-text
  38. v-text-field.md2(
  39. v-model='jwtAudience'
  40. outline
  41. prepend-icon='account_balance'
  42. :label='$t(`admin:auth.jwtAudience`)'
  43. :hint='$t(`admin:auth.jwtAudienceHint`)'
  44. persistent-hint
  45. )
  46. v-text-field.mt-3.md2(
  47. v-model='jwtExpiration'
  48. outline
  49. prepend-icon='schedule'
  50. :label='$t(`admin:auth.tokenExpiration`)'
  51. :hint='$t(`admin:auth.tokenExpirationHint`)'
  52. persistent-hint
  53. )
  54. v-text-field.mt-3.md2(
  55. v-model='jwtRenewablePeriod'
  56. outline
  57. prepend-icon='update'
  58. :label='$t(`admin:auth.tokenRenewalPeriod`)'
  59. :hint='$t(`admin:auth.tokenRenewalPeriodHint`)'
  60. persistent-hint
  61. )
  62. v-flex(xs12, lg9)
  63. v-card.wiki-form.animated.fadeInUp.wait-p2s
  64. v-toolbar(color='primary', dense, flat, dark)
  65. .subheading {{strategy.title}}
  66. v-card-text
  67. v-form
  68. .authlogo
  69. img(:src='strategy.logo', :alt='strategy.title')
  70. .caption.pt-3 {{strategy.description}}
  71. .caption.pb-3: a(:href='strategy.website') {{strategy.website}}
  72. i18next.body-2(path='admin:auth.strategyState', tag='div', v-if='strategy.isEnabled')
  73. v-chip(color='green', small, dark, label, place='state') {{$t('admin:auth.strategyStateActive')}}
  74. span(v-if='selectedStrategy === `local`', place='locked') {{$t('admin:auth.strategyStateLocked')}}
  75. span(v-else, place='locked', v-text='')
  76. i18next.body-2(path='admin:auth.strategyState', tag='div', v-else)
  77. v-chip(color='red', small, dark, label, place='state') {{$t('admin:auth.strategyStateInactive')}}
  78. v-divider.mt-3
  79. v-subheader.pl-0 Strategy Configuration
  80. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1'): em This strategy has no configuration options you can modify.
  81. template(v-else, v-for='cfg in strategy.config')
  82. v-select(
  83. v-if='cfg.value.type === "string" && cfg.value.enum'
  84. outline
  85. background-color='grey lighten-2'
  86. :items='cfg.value.enum'
  87. :key='cfg.key'
  88. :label='cfg.value.title'
  89. v-model='cfg.value.value'
  90. prepend-icon='settings_applications'
  91. :hint='cfg.value.hint ? cfg.value.hint : ""'
  92. persistent-hint
  93. :class='cfg.value.hint ? "mb-2" : ""'
  94. )
  95. v-switch.mb-3(
  96. v-else-if='cfg.value.type === "boolean"'
  97. :key='cfg.key'
  98. :label='cfg.value.title'
  99. v-model='cfg.value.value'
  100. color='primary'
  101. prepend-icon='settings_applications'
  102. :hint='cfg.value.hint ? cfg.value.hint : ""'
  103. persistent-hint
  104. )
  105. v-text-field(
  106. v-else
  107. outline
  108. background-color='grey lighten-2'
  109. :key='cfg.key'
  110. :label='cfg.value.title'
  111. v-model='cfg.value.value'
  112. prepend-icon='settings_applications'
  113. :hint='cfg.value.hint ? cfg.value.hint : ""'
  114. persistent-hint
  115. :class='cfg.value.hint ? "mb-2" : ""'
  116. )
  117. v-divider.mt-3
  118. v-subheader.pl-0 Registration
  119. .pr-3
  120. v-switch.ml-3(
  121. v-model='strategy.selfRegistration'
  122. label='Allow self-registration'
  123. color='primary'
  124. hint='Allow any user successfully authorized by the strategy to access the wiki.'
  125. persistent-hint
  126. )
  127. v-switch.ml-3(
  128. v-if='strategy.key === `local`'
  129. :disabled='!strategy.selfRegistration || true'
  130. v-model='strategy.recaptcha'
  131. label='Use reCAPTCHA by Google'
  132. color='primary'
  133. hint='Protects against spam robots and malicious registrations.'
  134. persistent-hint
  135. )
  136. v-combobox.ml-3.mt-3(
  137. label='Limit to specific email domains'
  138. v-model='strategy.domainWhitelist'
  139. prepend-icon='mail_outline'
  140. outline
  141. :disabled='!strategy.selfRegistration'
  142. hint='A list of domains authorized to register. The user email address domain must match one of these to gain access.'
  143. persistent-hint
  144. small-chips
  145. deletable-chips
  146. clearable
  147. multiple
  148. chips
  149. )
  150. v-autocomplete.mt-3.ml-3(
  151. outline
  152. :disabled='!strategy.selfRegistration'
  153. :items='groups'
  154. item-text='name'
  155. item-value='id'
  156. label='Assign to group'
  157. v-model='strategy.autoEnrollGroups'
  158. prepend-icon='people'
  159. hint='Automatically assign new users to these groups.'
  160. small-chips
  161. persistent-hint
  162. deletable-chips
  163. clearable
  164. multiple
  165. chips
  166. )
  167. template(v-if='strategy.useForm')
  168. v-divider.mt-3
  169. v-subheader.pl-0 Security
  170. v-switch.ml-3(
  171. v-model='strategy.recaptcha'
  172. :disabled='true'
  173. label='Force all users to use Two-Factor Authentication (2FA)'
  174. color='primary'
  175. hint='Users will be required to setup 2FA the first time they login and cannot be disabled by the user.'
  176. persistent-hint
  177. )
  178. v-card.mt-3.wiki-form.animated.fadeInUp.wait-p4s
  179. v-toolbar(color='primary', dense, flat, dark)
  180. .subheading Configuration Reference
  181. v-card-text
  182. .body-1 Some strategies may require some configuration values to be set on your provider. These are provided for reference only and may not be needed by the current strategy.
  183. v-alert.mt-3.radius-7(v-if='host.length < 8', color='red', outline, :value='true', icon='warning') You must set a valid #[strong Site URL] first! Click on #[strong General] in the left sidebar.
  184. .pa-3.mt-3.radius-7.grey(v-else, :class='$vuetify.dark ? `darken-3-d5` : `lighten-3`')
  185. .body-2 Allowed Web Origins
  186. .body-1 {{host}}
  187. v-divider.my-3
  188. .body-2 Callback URL / Redirect URI
  189. .body-1 {{host}}/login/{{strategy.key}}/callback
  190. v-divider.my-3
  191. .body-2 Login URL
  192. .body-1 {{host}}/login
  193. v-divider.my-3
  194. .body-2 Logout URL
  195. .body-1 {{host}}
  196. v-divider.my-3
  197. .body-2 Token Endpoint Authentication Method
  198. .body-1 HTTP-POST
  199. </template>
  200. <script>
  201. import _ from 'lodash'
  202. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  203. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  204. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  205. import hostQuery from 'gql/admin/auth/auth-query-host.gql'
  206. export default {
  207. filters: {
  208. startCase(val) { return _.startCase(val) }
  209. },
  210. data() {
  211. return {
  212. groups: [],
  213. strategies: [],
  214. selectedStrategy: '',
  215. host: '',
  216. strategy: {},
  217. jwtAudience: 'urn:wiki.js',
  218. jwtExpiration: '30m',
  219. jwtRenewablePeriod: '14d'
  220. }
  221. },
  222. computed: {
  223. activeStrategies() {
  224. return _.filter(this.strategies, 'isEnabled')
  225. }
  226. },
  227. watch: {
  228. selectedStrategy(newValue, oldValue) {
  229. this.strategy = _.find(this.strategies, ['key', newValue]) || {}
  230. },
  231. strategies(newValue, oldValue) {
  232. this.selectedStrategy = 'local'
  233. }
  234. },
  235. methods: {
  236. async refresh() {
  237. await this.$apollo.queries.strategies.refetch()
  238. this.$store.commit('showNotification', {
  239. message: 'List of strategies has been refreshed.',
  240. style: 'success',
  241. icon: 'cached'
  242. })
  243. },
  244. async save() {
  245. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  246. try {
  247. await this.$apollo.mutate({
  248. mutation: strategiesSaveMutation,
  249. variables: {
  250. config: {
  251. audience: this.jwtAudience,
  252. tokenExpiration: this.jwtExpiration,
  253. tokenRenewal: this.jwtRenewablePeriod
  254. },
  255. strategies: this.strategies.map(str => _.pick(str, [
  256. 'isEnabled',
  257. 'key',
  258. 'config',
  259. 'selfRegistration',
  260. 'domainWhitelist',
  261. 'autoEnrollGroups'
  262. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  263. }
  264. })
  265. this.$store.commit('showNotification', {
  266. message: 'Authentication configuration saved successfully.',
  267. style: 'success',
  268. icon: 'check'
  269. })
  270. } catch (err) {
  271. this.$store.commit('pushGraphError', err)
  272. }
  273. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  274. }
  275. },
  276. apollo: {
  277. strategies: {
  278. query: strategiesQuery,
  279. fetchPolicy: 'network-only',
  280. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({
  281. ...str,
  282. config: _.sortBy(str.config.map(cfg => ({
  283. ...cfg,
  284. value: JSON.parse(cfg.value)
  285. })), [t => t.value.order])
  286. })),
  287. watchLoading (isLoading) {
  288. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  289. }
  290. },
  291. groups: {
  292. query: groupsQuery,
  293. fetchPolicy: 'network-only',
  294. update: (data) => data.groups.list,
  295. watchLoading (isLoading) {
  296. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  297. }
  298. },
  299. host: {
  300. query: hostQuery,
  301. fetchPolicy: 'network-only',
  302. update: (data) => _.cloneDeep(data.site.config.host),
  303. watchLoading (isLoading) {
  304. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-host-refresh')
  305. }
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang='scss' scoped>
  311. .authlogo {
  312. width: 250px;
  313. height: 85px;
  314. float:right;
  315. display: flex;
  316. justify-content: flex-end;
  317. align-items: center;
  318. img {
  319. max-width: 100%;
  320. max-height: 50px;
  321. }
  322. }
  323. </style>