admin-auth.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:auth.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s.mr-3(outlined, color='grey', @click='refresh', large)
  12. v-icon mdi-refresh
  13. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  14. v-icon(left) mdi-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. .subtitle-1 {{$t('admin:auth.strategies')}}
  20. v-list(two-line, dense).py-0
  21. template(v-for='(str, idx) in strategies')
  22. v-list-item(:key='str.key', @click='selectedStrategy = str.key', :disabled='!str.isAvailable')
  23. v-list-item-avatar(size='24')
  24. v-icon(color='grey', v-if='!str.isAvailable') mdi-minus-box-outline
  25. v-icon(color='primary', v-else-if='str.isEnabled && str.key !== `local`', v-ripple, @click='str.isEnabled = false') mdi-checkbox-marked-outline
  26. v-icon(color='primary', v-else-if='str.isEnabled && str.key === `local`') mdi-checkbox-marked-outline
  27. v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') mdi-checkbox-blank-outline
  28. v-list-item-content
  29. v-list-item-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedStrategy === str.key ? `primary--text` : ``)') {{ str.title }}
  30. v-list-item-subtitle: .caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedStrategy === str.key ? `blue--text ` : ``)') {{ str.description }}
  31. v-list-item-avatar(v-if='selectedStrategy === str.key', size='24')
  32. v-icon.animated.fadeInLeft(color='primary', large) mdi-chevron-right
  33. v-divider(v-if='idx < strategies.length - 1')
  34. v-card.mt-3.animated.fadeInUp.wait-p2s
  35. v-toolbar(flat, color='primary', dark, dense)
  36. .subtitle-1 {{$t('admin:auth.globalAdvSettings')}}
  37. v-card-text
  38. v-text-field.md2(
  39. v-model='jwtAudience'
  40. outlined
  41. prepend-icon='mdi-account-group-outline'
  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. outlined
  49. prepend-icon='mdi-clock-outline'
  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. outlined
  57. prepend-icon='mdi-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.animated.fadeInUp.wait-p2s
  64. v-toolbar(color='primary', dense, flat, dark)
  65. .subtitle-1 {{strategy.title}}
  66. v-card-text
  67. v-form
  68. .authlogo
  69. img(:src='strategy.logo', :alt='strategy.title')
  70. .body-2.pt-3 {{strategy.description}}
  71. .body-2.pt-3.pb-5: 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. .overline.my-5 {{$t('admin:auth.strategyConfiguration')}}
  80. .body-2.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. outlined
  85. :items='cfg.value.enum'
  86. :key='cfg.key'
  87. :label='cfg.value.title'
  88. v-model='cfg.value.value'
  89. prepend-icon='mdi-settings-box'
  90. :hint='cfg.value.hint ? cfg.value.hint : ""'
  91. persistent-hint
  92. :class='cfg.value.hint ? "mb-2" : ""'
  93. )
  94. v-switch.mb-3(
  95. v-else-if='cfg.value.type === "boolean"'
  96. :key='cfg.key'
  97. :label='cfg.value.title'
  98. v-model='cfg.value.value'
  99. color='primary'
  100. prepend-icon='mdi-settings-box'
  101. :hint='cfg.value.hint ? cfg.value.hint : ""'
  102. persistent-hint
  103. )
  104. v-textarea(
  105. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  106. outlined
  107. :key='cfg.key'
  108. :label='cfg.value.title'
  109. v-model='cfg.value.value'
  110. prepend-icon='mdi-settings-box'
  111. :hint='cfg.value.hint ? cfg.value.hint : ""'
  112. persistent-hint
  113. :class='cfg.value.hint ? "mb-2" : ""'
  114. )
  115. v-text-field(
  116. v-else
  117. outlined
  118. :key='cfg.key'
  119. :label='cfg.value.title'
  120. v-model='cfg.value.value'
  121. prepend-icon='mdi-settings-box'
  122. :hint='cfg.value.hint ? cfg.value.hint : ""'
  123. persistent-hint
  124. :class='cfg.value.hint ? "mb-2" : ""'
  125. )
  126. v-divider.mt-3
  127. .overline.my-5 {{$t('admin:auth.registration')}}
  128. .pr-3
  129. v-switch.ml-3(
  130. v-model='strategy.selfRegistration'
  131. :label='$t(`admin:auth.selfRegistration`)'
  132. color='primary'
  133. :hint='$t(`admin:auth.selfRegistrationHint`)'
  134. persistent-hint
  135. )
  136. v-switch.ml-3(
  137. v-if='strategy.key === `local`'
  138. :disabled='!strategy.selfRegistration || true'
  139. v-model='strategy.recaptcha'
  140. label='Use reCAPTCHA by Google'
  141. color='primary'
  142. hint='Protects against spam robots and malicious registrations.'
  143. persistent-hint
  144. )
  145. v-combobox.ml-3.mt-3(
  146. :label='$t(`admin:auth.domainsWhitelist`)'
  147. v-model='strategy.domainWhitelist'
  148. prepend-icon='mdi-email-check-outline'
  149. outlined
  150. :disabled='!strategy.selfRegistration'
  151. :hint='$t(`admin:auth.domainsWhitelistHint`)'
  152. persistent-hint
  153. small-chips
  154. deletable-chips
  155. clearable
  156. multiple
  157. chips
  158. )
  159. v-autocomplete.mt-3.ml-3(
  160. outlined
  161. :disabled='!strategy.selfRegistration'
  162. :items='groups'
  163. item-text='name'
  164. item-value='id'
  165. :label='$t(`admin:auth.autoEnrollGroups`)'
  166. v-model='strategy.autoEnrollGroups'
  167. prepend-icon='mdi-account-group'
  168. :hint='$t(`admin:auth.autoEnrollGroupsHint`)'
  169. small-chips
  170. persistent-hint
  171. deletable-chips
  172. clearable
  173. multiple
  174. chips
  175. )
  176. template(v-if='strategy.useForm')
  177. v-divider.mt-3
  178. .overline.my-5 {{$t('admin:auth.security')}}
  179. v-switch.ml-3(
  180. v-model='strategy.recaptcha'
  181. :disabled='true'
  182. :label='$t(`admin:auth.force2fa`)'
  183. color='primary'
  184. :hint='$t(`admin:auth.force2faHint`)'
  185. persistent-hint
  186. )
  187. v-card.mt-4.wiki-form.animated.fadeInUp.wait-p4s
  188. v-toolbar(color='primary', dense, flat, dark)
  189. .subtitle-1 {{$t('admin:auth.configReference')}}
  190. v-card-text
  191. .body-2 {{$t('admin:auth.configReferenceSubtitle')}}
  192. v-alert.mt-3.radius-7(v-if='host.length < 8', color='red', outlined, :value='true', icon='mdi-alert')
  193. i18next(path='admin:auth.siteUrlNotSetup', tag='span')
  194. strong(place='siteUrl') {{$t('admin:general.siteUrl')}}
  195. strong(place='general') {{$t('admin:general.title')}}
  196. .pa-3.mt-3.radius-7.grey(v-else, :class='$vuetify.dark ? `darken-3-d5` : `lighten-3`')
  197. .body-2: strong {{$t('admin:auth.allowedWebOrigins')}}
  198. .body-2 {{host}}
  199. v-divider.my-3
  200. .body-2: strong {{$t('admin:auth.callbackUrl')}}
  201. .body-2 {{host}}/login/{{strategy.key}}/callback
  202. v-divider.my-3
  203. .body-2: strong {{$t('admin:auth.loginUrl')}}
  204. .body-2 {{host}}/login
  205. v-divider.my-3
  206. .body-2: strong {{$t('admin:auth.logoutUrl')}}
  207. .body-2 {{host}}
  208. v-divider.my-3
  209. .body-2: strong {{$t('admin:auth.tokenEndpointAuthMethod')}}
  210. .body-2 HTTP-POST
  211. </template>
  212. <script>
  213. import _ from 'lodash'
  214. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  215. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  216. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  217. import hostQuery from 'gql/admin/auth/auth-query-host.gql'
  218. export default {
  219. filters: {
  220. startCase(val) { return _.startCase(val) }
  221. },
  222. data() {
  223. return {
  224. groups: [],
  225. strategies: [],
  226. selectedStrategy: '',
  227. host: '',
  228. strategy: {},
  229. jwtAudience: 'urn:wiki.js',
  230. jwtExpiration: '30m',
  231. jwtRenewablePeriod: '14d'
  232. }
  233. },
  234. computed: {
  235. activeStrategies() {
  236. return _.filter(this.strategies, 'isEnabled')
  237. }
  238. },
  239. watch: {
  240. selectedStrategy(newValue, oldValue) {
  241. this.strategy = _.find(this.strategies, ['key', newValue]) || {}
  242. },
  243. strategies(newValue, oldValue) {
  244. this.selectedStrategy = 'local'
  245. }
  246. },
  247. methods: {
  248. async refresh() {
  249. await this.$apollo.queries.strategies.refetch()
  250. this.$store.commit('showNotification', {
  251. message: this.$t('admin:auth.refreshSuccess'),
  252. style: 'success',
  253. icon: 'cached'
  254. })
  255. },
  256. async save() {
  257. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  258. try {
  259. await this.$apollo.mutate({
  260. mutation: strategiesSaveMutation,
  261. variables: {
  262. config: {
  263. audience: this.jwtAudience,
  264. tokenExpiration: this.jwtExpiration,
  265. tokenRenewal: this.jwtRenewablePeriod
  266. },
  267. strategies: this.strategies.map(str => _.pick(str, [
  268. 'isEnabled',
  269. 'key',
  270. 'config',
  271. 'selfRegistration',
  272. 'domainWhitelist',
  273. 'autoEnrollGroups'
  274. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  275. }
  276. })
  277. this.$store.commit('showNotification', {
  278. message: this.$t('admin:auth.saveSuccess'),
  279. style: 'success',
  280. icon: 'check'
  281. })
  282. } catch (err) {
  283. this.$store.commit('pushGraphError', err)
  284. }
  285. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  286. }
  287. },
  288. apollo: {
  289. strategies: {
  290. query: strategiesQuery,
  291. fetchPolicy: 'network-only',
  292. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({
  293. ...str,
  294. config: _.sortBy(str.config.map(cfg => ({
  295. ...cfg,
  296. value: JSON.parse(cfg.value)
  297. })), [t => t.value.order])
  298. })),
  299. watchLoading (isLoading) {
  300. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  301. }
  302. },
  303. groups: {
  304. query: groupsQuery,
  305. fetchPolicy: 'network-only',
  306. update: (data) => data.groups.list,
  307. watchLoading (isLoading) {
  308. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  309. }
  310. },
  311. host: {
  312. query: hostQuery,
  313. fetchPolicy: 'network-only',
  314. update: (data) => _.cloneDeep(data.site.config.host),
  315. watchLoading (isLoading) {
  316. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-host-refresh')
  317. }
  318. }
  319. }
  320. }
  321. </script>
  322. <style lang='scss' scoped>
  323. .authlogo {
  324. width: 250px;
  325. height: 85px;
  326. float:right;
  327. display: flex;
  328. justify-content: flex-end;
  329. align-items: center;
  330. margin-left: 16px;
  331. img {
  332. max-width: 100%;
  333. max-height: 50px;
  334. }
  335. }
  336. </style>