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.

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