diff options
Diffstat (limited to 'packages/tests/fixtures/peertube-plugin-test-external-auth-one/main.js')
-rw-r--r-- | packages/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/packages/tests/fixtures/peertube-plugin-test-external-auth-one/main.js b/packages/tests/fixtures/peertube-plugin-test-external-auth-one/main.js new file mode 100644 index 000000000..58bc27661 --- /dev/null +++ b/packages/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | |||
@@ -0,0 +1,85 @@ | |||
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 | |||
15 | result.userAuthenticated({ | ||
16 | req, | ||
17 | res, | ||
18 | username, | ||
19 | email: username + '@example.com' | ||
20 | }) | ||
21 | } | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | { | ||
26 | const result = registerExternalAuth({ | ||
27 | authName: 'external-auth-2', | ||
28 | authDisplayName: () => 'External Auth 2', | ||
29 | onAuthRequest: (req, res) => { | ||
30 | result.userAuthenticated({ | ||
31 | req, | ||
32 | res, | ||
33 | username: 'kefka', | ||
34 | email: 'kefka@example.com', | ||
35 | role: 0, | ||
36 | displayName: 'Kefka Palazzo', | ||
37 | adminFlags: 1, | ||
38 | videoQuota: 42000, | ||
39 | videoQuotaDaily: 42100, | ||
40 | |||
41 | // Always use new value except for videoQuotaDaily field | ||
42 | userUpdater: ({ fieldName, currentValue, newValue }) => { | ||
43 | if (fieldName === 'videoQuotaDaily') return currentValue | ||
44 | |||
45 | return newValue | ||
46 | } | ||
47 | }) | ||
48 | }, | ||
49 | hookTokenValidity: (options) => { | ||
50 | if (options.type === 'refresh') { | ||
51 | return { valid: false } | ||
52 | } | ||
53 | |||
54 | if (options.type === 'access') { | ||
55 | const token = options.token | ||
56 | const now = new Date() | ||
57 | now.setTime(now.getTime() - 5000) | ||
58 | |||
59 | const createdAt = new Date(token.createdAt) | ||
60 | |||
61 | return { valid: createdAt.getTime() >= now.getTime() } | ||
62 | } | ||
63 | |||
64 | return { valid: true } | ||
65 | } | ||
66 | }) | ||
67 | } | ||
68 | |||
69 | settingsManager.onSettingsChange(settings => { | ||
70 | if (settings.disableKefka) { | ||
71 | unregisterExternalAuth('external-auth-2') | ||
72 | } | ||
73 | }) | ||
74 | } | ||
75 | |||
76 | async function unregister () { | ||
77 | return | ||
78 | } | ||
79 | |||
80 | module.exports = { | ||
81 | register, | ||
82 | unregister | ||
83 | } | ||
84 | |||
85 | // ########################################################################### | ||