ニジカ投稿局 https://tv.nizika.tv
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.
 
 
 
 
 

86 lines
2.0 KiB

  1. async function register ({
  2. registerExternalAuth,
  3. peertubeHelpers,
  4. settingsManager,
  5. unregisterExternalAuth
  6. }) {
  7. {
  8. const result = registerExternalAuth({
  9. authName: 'external-auth-1',
  10. authDisplayName: () => 'External Auth 1',
  11. onLogout: user => peertubeHelpers.logger.info('On logout %s', user.username),
  12. onAuthRequest: (req, res) => {
  13. const username = req.query.username
  14. result.userAuthenticated({
  15. req,
  16. res,
  17. username,
  18. email: username + '@example.com'
  19. })
  20. }
  21. })
  22. }
  23. {
  24. const result = registerExternalAuth({
  25. authName: 'external-auth-2',
  26. authDisplayName: () => 'External Auth 2',
  27. onAuthRequest: (req, res) => {
  28. result.userAuthenticated({
  29. req,
  30. res,
  31. username: 'kefka',
  32. email: 'kefka@example.com',
  33. role: 0,
  34. displayName: 'Kefka Palazzo',
  35. adminFlags: 1,
  36. videoQuota: 42000,
  37. videoQuotaDaily: 42100,
  38. // Always use new value except for videoQuotaDaily field
  39. userUpdater: ({ fieldName, currentValue, newValue }) => {
  40. if (fieldName === 'videoQuotaDaily') return currentValue
  41. return newValue
  42. }
  43. })
  44. },
  45. hookTokenValidity: (options) => {
  46. if (options.type === 'refresh') {
  47. return { valid: false }
  48. }
  49. if (options.type === 'access') {
  50. const token = options.token
  51. const now = new Date()
  52. now.setTime(now.getTime() - 5000)
  53. const createdAt = new Date(token.createdAt)
  54. return { valid: createdAt.getTime() >= now.getTime() }
  55. }
  56. return { valid: true }
  57. }
  58. })
  59. }
  60. settingsManager.onSettingsChange(settings => {
  61. if (settings.disableKefka) {
  62. unregisterExternalAuth('external-auth-2')
  63. }
  64. })
  65. }
  66. async function unregister () {
  67. return
  68. }
  69. module.exports = {
  70. register,
  71. unregister
  72. }
  73. // ###########################################################################