authentication.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const _ = require('lodash')
  2. const fs = require('fs-extra')
  3. const path = require('path')
  4. /* global WIKI */
  5. module.exports = {
  6. Query: {
  7. async authentication() { return {} }
  8. },
  9. Mutation: {
  10. async authentication() { return {} }
  11. },
  12. AuthenticationQuery: {
  13. providers(obj, args, context, info) {
  14. switch (args.mode) {
  15. case 'active':
  16. let strategies = _.chain(WIKI.auth.strategies).map(str => {
  17. return {
  18. key: str.key,
  19. title: str.title,
  20. useForm: str.useForm
  21. }
  22. }).sortBy(['title']).value()
  23. let localStrategy = _.remove(strategies, str => str.key === 'local')
  24. return _.concat(localStrategy, strategies)
  25. case 'all':
  26. break
  27. default:
  28. return null
  29. }
  30. }
  31. },
  32. AuthenticationProvider: {
  33. icon (ap, args) {
  34. return fs.readFileAsync(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${ap.key}.svg`), 'utf8').catch(err => {
  35. if (err.code === 'ENOENT') {
  36. return null
  37. }
  38. throw err
  39. })
  40. }
  41. }
  42. }