admin-auth.vue 14 KB

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