diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-22 16:07:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 7fed637506043e4432cbebe041ada0625171cceb (patch) | |
tree | 07f174e17c4b4a0b3d43a0fa6944865c06234338 /server/lib/plugins/register-helpers-store.ts | |
parent | 8d4197637868d5cde49434e937186b57e40f4b2b (diff) | |
download | PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.gz PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.zst PeerTube-7fed637506043e4432cbebe041ada0625171cceb.zip |
Begin auth plugin support
Diffstat (limited to 'server/lib/plugins/register-helpers-store.ts')
-rw-r--r-- | server/lib/plugins/register-helpers-store.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts index 5ca52b151..7e827401f 100644 --- a/server/lib/plugins/register-helpers-store.ts +++ b/server/lib/plugins/register-helpers-store.ts | |||
@@ -20,6 +20,12 @@ import { RegisterServerSettingOptions } from '@shared/models/plugins/register-se | |||
20 | import * as express from 'express' | 20 | import * as express from 'express' |
21 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' | 21 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' |
22 | import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' | 22 | import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' |
23 | import { | ||
24 | RegisterServerAuthExternalOptions, | ||
25 | RegisterServerAuthExternalResult, | ||
26 | RegisterServerAuthPassOptions | ||
27 | } from '@shared/models/plugins/register-server-auth.model' | ||
28 | import { onExternalAuthPlugin } from '@server/lib/auth' | ||
23 | 29 | ||
24 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' | 30 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' |
25 | type VideoConstant = { [key in number | string]: string } | 31 | type VideoConstant = { [key in number | string]: string } |
@@ -42,6 +48,9 @@ export class RegisterHelpersStore { | |||
42 | 48 | ||
43 | private readonly settings: RegisterServerSettingOptions[] = [] | 49 | private readonly settings: RegisterServerSettingOptions[] = [] |
44 | 50 | ||
51 | private readonly idAndPassAuths: RegisterServerAuthPassOptions[] = [] | ||
52 | private readonly externalAuths: RegisterServerAuthExternalOptions[] = [] | ||
53 | |||
45 | private readonly router: express.Router | 54 | private readonly router: express.Router |
46 | 55 | ||
47 | constructor ( | 56 | constructor ( |
@@ -69,6 +78,9 @@ export class RegisterHelpersStore { | |||
69 | const videoPrivacyManager = this.buildVideoPrivacyManager() | 78 | const videoPrivacyManager = this.buildVideoPrivacyManager() |
70 | const playlistPrivacyManager = this.buildPlaylistPrivacyManager() | 79 | const playlistPrivacyManager = this.buildPlaylistPrivacyManager() |
71 | 80 | ||
81 | const registerIdAndPassAuth = this.buildRegisterIdAndPassAuth() | ||
82 | const registerExternalAuth = this.buildRegisterExternalAuth() | ||
83 | |||
72 | const peertubeHelpers = buildPluginHelpers(this.npmName) | 84 | const peertubeHelpers = buildPluginHelpers(this.npmName) |
73 | 85 | ||
74 | return { | 86 | return { |
@@ -87,6 +99,9 @@ export class RegisterHelpersStore { | |||
87 | videoPrivacyManager, | 99 | videoPrivacyManager, |
88 | playlistPrivacyManager, | 100 | playlistPrivacyManager, |
89 | 101 | ||
102 | registerIdAndPassAuth, | ||
103 | registerExternalAuth, | ||
104 | |||
90 | peertubeHelpers | 105 | peertubeHelpers |
91 | } | 106 | } |
92 | } | 107 | } |
@@ -125,6 +140,14 @@ export class RegisterHelpersStore { | |||
125 | return this.router | 140 | return this.router |
126 | } | 141 | } |
127 | 142 | ||
143 | getIdAndPassAuths () { | ||
144 | return this.idAndPassAuths | ||
145 | } | ||
146 | |||
147 | getExternalAuths () { | ||
148 | return this.externalAuths | ||
149 | } | ||
150 | |||
128 | private buildGetRouter () { | 151 | private buildGetRouter () { |
129 | return () => this.router | 152 | return () => this.router |
130 | } | 153 | } |
@@ -146,6 +169,26 @@ export class RegisterHelpersStore { | |||
146 | } | 169 | } |
147 | } | 170 | } |
148 | 171 | ||
172 | private buildRegisterIdAndPassAuth () { | ||
173 | return (options: RegisterServerAuthPassOptions) => { | ||
174 | this.idAndPassAuths.push(options) | ||
175 | } | ||
176 | } | ||
177 | |||
178 | private buildRegisterExternalAuth () { | ||
179 | const self = this | ||
180 | |||
181 | return (options: RegisterServerAuthExternalOptions) => { | ||
182 | this.externalAuths.push(options) | ||
183 | |||
184 | return { | ||
185 | onAuth (options: { username: string, email: string }): void { | ||
186 | onExternalAuthPlugin(self.npmName, options.username, options.email) | ||
187 | } | ||
188 | } as RegisterServerAuthExternalResult | ||
189 | } | ||
190 | } | ||
191 | |||
149 | private buildSettingsManager (): PluginSettingsManager { | 192 | private buildSettingsManager (): PluginSettingsManager { |
150 | return { | 193 | return { |
151 | getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name), | 194 | getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name), |