1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Begin auth plugin support

This commit is contained in:
Chocobozzz 2020-04-22 16:07:04 +02:00 committed by Chocobozzz
parent 8d41976378
commit 7fed637506
23 changed files with 604 additions and 74 deletions

View file

@ -20,6 +20,12 @@ import { RegisterServerSettingOptions } from '@shared/models/plugins/register-se
import * as express from 'express'
import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model'
import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model'
import {
RegisterServerAuthExternalOptions,
RegisterServerAuthExternalResult,
RegisterServerAuthPassOptions
} from '@shared/models/plugins/register-server-auth.model'
import { onExternalAuthPlugin } from '@server/lib/auth'
type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy'
type VideoConstant = { [key in number | string]: string }
@ -42,6 +48,9 @@ export class RegisterHelpersStore {
private readonly settings: RegisterServerSettingOptions[] = []
private readonly idAndPassAuths: RegisterServerAuthPassOptions[] = []
private readonly externalAuths: RegisterServerAuthExternalOptions[] = []
private readonly router: express.Router
constructor (
@ -69,6 +78,9 @@ export class RegisterHelpersStore {
const videoPrivacyManager = this.buildVideoPrivacyManager()
const playlistPrivacyManager = this.buildPlaylistPrivacyManager()
const registerIdAndPassAuth = this.buildRegisterIdAndPassAuth()
const registerExternalAuth = this.buildRegisterExternalAuth()
const peertubeHelpers = buildPluginHelpers(this.npmName)
return {
@ -87,6 +99,9 @@ export class RegisterHelpersStore {
videoPrivacyManager,
playlistPrivacyManager,
registerIdAndPassAuth,
registerExternalAuth,
peertubeHelpers
}
}
@ -125,6 +140,14 @@ export class RegisterHelpersStore {
return this.router
}
getIdAndPassAuths () {
return this.idAndPassAuths
}
getExternalAuths () {
return this.externalAuths
}
private buildGetRouter () {
return () => this.router
}
@ -146,6 +169,26 @@ export class RegisterHelpersStore {
}
}
private buildRegisterIdAndPassAuth () {
return (options: RegisterServerAuthPassOptions) => {
this.idAndPassAuths.push(options)
}
}
private buildRegisterExternalAuth () {
const self = this
return (options: RegisterServerAuthExternalOptions) => {
this.externalAuths.push(options)
return {
onAuth (options: { username: string, email: string }): void {
onExternalAuthPlugin(self.npmName, options.username, options.email)
}
} as RegisterServerAuthExternalResult
}
}
private buildSettingsManager (): PluginSettingsManager {
return {
getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name),