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.

328 lines
12 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 Authentication
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s Configure the authentication settings of your wiki
  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 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', v-ripple, @click='str.key !== `local` && (str.isEnabled = false)') check_box
  26. v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') check_box_outline_blank
  27. v-list-tile-content
  28. v-list-tile-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedStrategy === str.key ? `primary--text` : ``)') {{ str.title }}
  29. v-list-tile-sub-title.caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedStrategy === str.key ? `blue--text ` : ``)') {{ str.description }}
  30. v-list-tile-avatar(v-if='selectedStrategy === str.key')
  31. v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
  32. v-divider(v-if='idx < strategies.length - 1')
  33. v-card.wiki-form.mt-3.animated.fadeInUp.wait-p2s
  34. v-toolbar(flat, color='primary', dark, dense)
  35. .subheading Global Advanced settings
  36. v-card-text
  37. v-text-field.md2(
  38. v-model='jwtAudience'
  39. outline
  40. prepend-icon='account_balance'
  41. label='JWT Audience'
  42. hint='Audience URN used in JWT issued upon login. Usually your domain name. (e.g. urn:your.domain.com)'
  43. persistent-hint
  44. )
  45. v-text-field.mt-3.md2(
  46. v-model='jwtExpiration'
  47. outline
  48. prepend-icon='schedule'
  49. label='Token Expiration'
  50. hint='The expiration period of a token until it must be renewed. (default: 30m)'
  51. persistent-hint
  52. )
  53. v-text-field.mt-3.md2(
  54. v-model='jwtRenewablePeriod'
  55. outline
  56. prepend-icon='update'
  57. label='Token Renewal Period'
  58. hint='The maximum period a token can be renewed when expired. (default: 14d)'
  59. persistent-hint
  60. )
  61. v-flex(xs12, lg9)
  62. v-card.wiki-form.animated.fadeInUp.wait-p2s
  63. v-toolbar(color='primary', dense, flat, dark)
  64. .subheading {{strategy.title}}
  65. v-card-text
  66. v-form
  67. .authlogo
  68. img(:src='strategy.logo', :alt='strategy.title')
  69. .caption.pt-3 {{strategy.description}}
  70. .caption.pb-3: a(:href='strategy.website') {{strategy.website}}
  71. v-divider.mt-3
  72. v-subheader.pl-0 Strategy Configuration
  73. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1'): em This strategy has no configuration options you can modify.
  74. template(v-else, v-for='cfg in strategy.config')
  75. v-select(
  76. v-if='cfg.value.type === "string" && cfg.value.enum'
  77. outline
  78. background-color='grey lighten-2'
  79. :items='cfg.value.enum'
  80. :key='cfg.key'
  81. :label='cfg.value.title'
  82. v-model='cfg.value.value'
  83. prepend-icon='settings_applications'
  84. :hint='cfg.value.hint ? cfg.value.hint : ""'
  85. persistent-hint
  86. :class='cfg.value.hint ? "mb-2" : ""'
  87. )
  88. v-switch.mb-3(
  89. v-else-if='cfg.value.type === "boolean"'
  90. :key='cfg.key'
  91. :label='cfg.value.title'
  92. v-model='cfg.value.value'
  93. color='primary'
  94. prepend-icon='settings_applications'
  95. :hint='cfg.value.hint ? cfg.value.hint : ""'
  96. persistent-hint
  97. )
  98. v-text-field(
  99. v-else
  100. outline
  101. background-color='grey lighten-2'
  102. :key='cfg.key'
  103. :label='cfg.value.title'
  104. v-model='cfg.value.value'
  105. prepend-icon='settings_applications'
  106. :hint='cfg.value.hint ? cfg.value.hint : ""'
  107. persistent-hint
  108. :class='cfg.value.hint ? "mb-2" : ""'
  109. )
  110. v-divider.mt-3
  111. v-subheader.pl-0 Registration
  112. .pr-3
  113. v-switch.ml-3(
  114. v-model='strategy.selfRegistration'
  115. label='Allow self-registration'
  116. color='primary'
  117. hint='Allow any user successfully authorized by the strategy to access the wiki.'
  118. persistent-hint
  119. )
  120. v-switch.ml-3(
  121. v-if='strategy.useForm'
  122. :disabled='!strategy.selfRegistration || true'
  123. v-model='strategy.recaptcha'
  124. label='Use reCAPTCHA by Google'
  125. color='primary'
  126. hint='Protects against spam robots and malicious registrations.'
  127. persistent-hint
  128. )
  129. v-combobox.ml-3.mt-3(
  130. label='Limit to specific email domains'
  131. v-model='strategy.domainWhitelist'
  132. prepend-icon='mail_outline'
  133. outline
  134. :disabled='!strategy.selfRegistration'
  135. hint='A list of domains authorized to register. The user email address domain must match one of these to gain access.'
  136. persistent-hint
  137. small-chips
  138. deletable-chips
  139. clearable
  140. multiple
  141. chips
  142. )
  143. v-autocomplete.mt-3.ml-3(
  144. outline
  145. :disabled='!strategy.selfRegistration'
  146. :items='groups'
  147. item-text='name'
  148. item-value='id'
  149. label='Assign to group'
  150. v-model='strategy.autoEnrollGroups'
  151. prepend-icon='people'
  152. hint='Automatically assign new users to these groups.'
  153. small-chips
  154. persistent-hint
  155. deletable-chips
  156. clearable
  157. multiple
  158. chips
  159. )
  160. template(v-if='strategy.useForm')
  161. v-divider.mt-3
  162. v-subheader.pl-0 Security
  163. v-switch.ml-3(
  164. v-model='strategy.recaptcha'
  165. :disabled='true'
  166. label='Force all users to use Two-Factor Authentication (2FA)'
  167. color='primary'
  168. hint='Users will be required to setup 2FA the first time they login and cannot be disabled by the user.'
  169. persistent-hint
  170. )
  171. v-card.mt-3.wiki-form.animated.fadeInUp.wait-p4s
  172. v-toolbar(color='primary', dense, flat, dark)
  173. .subheading Configuration Reference
  174. v-card-text
  175. .body-1 Some strategies may require some configuration values to be set on your provider.
  176. v-alert.mt-3.radius-7(v-if='host.length < 8', color='red', outline, :value='true', icon='warning') You must set a valid #[strong Site URL] first! Click on #[strong General] in the left sidebar.
  177. .pa-3.mt-3.radius-7.grey(v-else, :class='$vuetify.dark ? `darken-3-d5` : `lighten-3`')
  178. .body-2 Allowed Web Origins
  179. .body-1 {{host}}
  180. v-divider.my-3
  181. .body-2 Callback URL / Redirect URI
  182. .body-1 {{host}}/login/{{strategy.key}}/callback
  183. v-divider.my-3
  184. .body-2 Login URL
  185. .body-1 {{host}}/login
  186. v-divider.my-3
  187. .body-2 Logout URL
  188. .body-1 {{host}}
  189. v-divider.my-3
  190. .body-2 Token Endpoint Authentication Method
  191. .body-1 HTTP-POST
  192. </template>
  193. <script>
  194. import _ from 'lodash'
  195. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  196. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  197. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  198. import hostQuery from 'gql/admin/auth/auth-query-host.gql'
  199. export default {
  200. filters: {
  201. startCase(val) { return _.startCase(val) }
  202. },
  203. data() {
  204. return {
  205. groups: [],
  206. strategies: [],
  207. selectedStrategy: '',
  208. host: '',
  209. strategy: {},
  210. jwtAudience: 'urn:wiki.js',
  211. jwtExpiration: '30m',
  212. jwtRenewablePeriod: '14d'
  213. }
  214. },
  215. computed: {
  216. activeStrategies() {
  217. return _.filter(this.strategies, 'isEnabled')
  218. }
  219. },
  220. watch: {
  221. selectedStrategy(newValue, oldValue) {
  222. this.strategy = _.find(this.strategies, ['key', newValue]) || {}
  223. },
  224. strategies(newValue, oldValue) {
  225. this.selectedStrategy = 'local'
  226. }
  227. },
  228. methods: {
  229. async refresh() {
  230. await this.$apollo.queries.strategies.refetch()
  231. this.$store.commit('showNotification', {
  232. message: 'List of strategies has been refreshed.',
  233. style: 'success',
  234. icon: 'cached'
  235. })
  236. },
  237. async save() {
  238. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  239. try {
  240. await this.$apollo.mutate({
  241. mutation: strategiesSaveMutation,
  242. variables: {
  243. config: {
  244. audience: this.jwtAudience,
  245. tokenExpiration: this.jwtExpiration,
  246. tokenRenewal: this.jwtRenewablePeriod
  247. },
  248. strategies: this.strategies.map(str => _.pick(str, [
  249. 'isEnabled',
  250. 'key',
  251. 'config',
  252. 'selfRegistration',
  253. 'domainWhitelist',
  254. 'autoEnrollGroups'
  255. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  256. }
  257. })
  258. this.$store.commit('showNotification', {
  259. message: 'Authentication configuration saved successfully.',
  260. style: 'success',
  261. icon: 'check'
  262. })
  263. } catch (err) {
  264. this.$store.commit('pushGraphError', err)
  265. }
  266. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  267. }
  268. },
  269. apollo: {
  270. strategies: {
  271. query: strategiesQuery,
  272. fetchPolicy: 'network-only',
  273. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({
  274. ...str,
  275. config: _.sortBy(str.config.map(cfg => ({
  276. ...cfg,
  277. value: JSON.parse(cfg.value)
  278. })), [t => t.value.order])
  279. })),
  280. watchLoading (isLoading) {
  281. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  282. }
  283. },
  284. groups: {
  285. query: groupsQuery,
  286. fetchPolicy: 'network-only',
  287. update: (data) => data.groups.list,
  288. watchLoading (isLoading) {
  289. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  290. }
  291. },
  292. host: {
  293. query: hostQuery,
  294. fetchPolicy: 'network-only',
  295. update: (data) => _.cloneDeep(data.site.config.host),
  296. watchLoading (isLoading) {
  297. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-host-refresh')
  298. }
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang='scss' scoped>
  304. .authlogo {
  305. width: 250px;
  306. height: 85px;
  307. float:right;
  308. display: flex;
  309. justify-content: flex-end;
  310. align-items: center;
  311. img {
  312. max-width: 100%;
  313. max-height: 50px;
  314. }
  315. }
  316. </style>