admin-auth.vue 14 KB

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