admin-auth.vue 14 KB

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