admin-auth.vue 13 KB

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