admin-auth.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 {{$t('admin:auth.strategyConfiguration')}}
  80. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1'): em {{$t('admin:auth.strategyNoConfiguration')}}
  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 {{$t('admin:auth.registration')}}
  119. .pr-3
  120. v-switch.ml-3(
  121. v-model='strategy.selfRegistration'
  122. :label='$t(`admin:auth.selfRegistration`)'
  123. color='primary'
  124. :hint='$t(`admin:auth.selfRegistrationHint`)'
  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='$t(`admin:auth.domainsWhitelist`)'
  138. v-model='strategy.domainWhitelist'
  139. prepend-icon='mail_outline'
  140. outline
  141. :disabled='!strategy.selfRegistration'
  142. :hint='$t(`admin:auth.domainsWhitelistHint`)'
  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='$t(`admin:auth.autoEnrollGroups`)'
  157. v-model='strategy.autoEnrollGroups'
  158. prepend-icon='people'
  159. :hint='$t(`admin:auth.autoEnrollGroupsHint`)'
  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 {{$t('admin:auth.security')}}
  170. v-switch.ml-3(
  171. v-model='strategy.recaptcha'
  172. :disabled='true'
  173. :label='$t(`admin:auth.force2fa`)'
  174. color='primary'
  175. :hint='$t(`admin:auth.force2faHint`)'
  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 {{$t('admin:auth.configReference')}}
  181. v-card-text
  182. .body-1 {{$t('admin:auth.configReferenceSubtitle')}}
  183. v-alert.mt-3.radius-7(v-if='host.length < 8', color='red', outline, :value='true', icon='warning')
  184. i18next(path='admin:auth.siteUrlNotSetup', tag='span')
  185. strong(place='siteUrl') {{$t('admin:general.siteUrl')}}
  186. strong(place='general') {{$t('admin:general.title')}}
  187. .pa-3.mt-3.radius-7.grey(v-else, :class='$vuetify.dark ? `darken-3-d5` : `lighten-3`')
  188. .body-2 {{$t('admin:auth.allowedWebOrigins')}}
  189. .body-1 {{host}}
  190. v-divider.my-3
  191. .body-2 {{$t('admin:auth.callbackUrl')}}
  192. .body-1 {{host}}/login/{{strategy.key}}/callback
  193. v-divider.my-3
  194. .body-2 {{$t('admin:auth.loginUrl')}}
  195. .body-1 {{host}}/login
  196. v-divider.my-3
  197. .body-2 {{$t('admin:auth.logoutUrl')}}
  198. .body-1 {{host}}
  199. v-divider.my-3
  200. .body-2 {{$t('admin:auth.tokenEndpointAuthMethod')}}
  201. .body-1 HTTP-POST
  202. </template>
  203. <script>
  204. import _ from 'lodash'
  205. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  206. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  207. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  208. import hostQuery from 'gql/admin/auth/auth-query-host.gql'
  209. export default {
  210. filters: {
  211. startCase(val) { return _.startCase(val) }
  212. },
  213. data() {
  214. return {
  215. groups: [],
  216. strategies: [],
  217. selectedStrategy: '',
  218. host: '',
  219. strategy: {},
  220. jwtAudience: 'urn:wiki.js',
  221. jwtExpiration: '30m',
  222. jwtRenewablePeriod: '14d'
  223. }
  224. },
  225. computed: {
  226. activeStrategies() {
  227. return _.filter(this.strategies, 'isEnabled')
  228. }
  229. },
  230. watch: {
  231. selectedStrategy(newValue, oldValue) {
  232. this.strategy = _.find(this.strategies, ['key', newValue]) || {}
  233. },
  234. strategies(newValue, oldValue) {
  235. this.selectedStrategy = 'local'
  236. }
  237. },
  238. methods: {
  239. async refresh() {
  240. await this.$apollo.queries.strategies.refetch()
  241. this.$store.commit('showNotification', {
  242. message: 'List of strategies has been refreshed.',
  243. style: 'success',
  244. icon: 'cached'
  245. })
  246. },
  247. async save() {
  248. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  249. try {
  250. await this.$apollo.mutate({
  251. mutation: strategiesSaveMutation,
  252. variables: {
  253. config: {
  254. audience: this.jwtAudience,
  255. tokenExpiration: this.jwtExpiration,
  256. tokenRenewal: this.jwtRenewablePeriod
  257. },
  258. strategies: this.strategies.map(str => _.pick(str, [
  259. 'isEnabled',
  260. 'key',
  261. 'config',
  262. 'selfRegistration',
  263. 'domainWhitelist',
  264. 'autoEnrollGroups'
  265. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  266. }
  267. })
  268. this.$store.commit('showNotification', {
  269. message: 'Authentication configuration saved successfully.',
  270. style: 'success',
  271. icon: 'check'
  272. })
  273. } catch (err) {
  274. this.$store.commit('pushGraphError', err)
  275. }
  276. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  277. }
  278. },
  279. apollo: {
  280. strategies: {
  281. query: strategiesQuery,
  282. fetchPolicy: 'network-only',
  283. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({
  284. ...str,
  285. config: _.sortBy(str.config.map(cfg => ({
  286. ...cfg,
  287. value: JSON.parse(cfg.value)
  288. })), [t => t.value.order])
  289. })),
  290. watchLoading (isLoading) {
  291. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  292. }
  293. },
  294. groups: {
  295. query: groupsQuery,
  296. fetchPolicy: 'network-only',
  297. update: (data) => data.groups.list,
  298. watchLoading (isLoading) {
  299. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  300. }
  301. },
  302. host: {
  303. query: hostQuery,
  304. fetchPolicy: 'network-only',
  305. update: (data) => _.cloneDeep(data.site.config.host),
  306. watchLoading (isLoading) {
  307. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-host-refresh')
  308. }
  309. }
  310. }
  311. }
  312. </script>
  313. <style lang='scss' scoped>
  314. .authlogo {
  315. width: 250px;
  316. height: 85px;
  317. float:right;
  318. display: flex;
  319. justify-content: flex-end;
  320. align-items: center;
  321. img {
  322. max-width: 100%;
  323. max-height: 50px;
  324. }
  325. }
  326. </style>