You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
14 KiB

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