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.

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