]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js
Add ability for auth plugins to hook tokens validity
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test-id-pass-auth-two / main.js
CommitLineData
7fed6375
C
1async function register ({
2 registerIdAndPassAuth,
3 peertubeHelpers
4}) {
5 registerIdAndPassAuth({
e1c55031 6 authName: 'laguna-auth',
7fed6375
C
7
8 onLogout: () => {
9 peertubeHelpers.logger.info('On logout for auth 2 - 1')
10 },
11
12 getWeight: () => 30,
13
e307e4fc
C
14 hookTokenValidity: (options) => {
15 if (options.type === 'refresh') {
16 return { valid: false }
17 }
18
19 if (options.type === 'access') {
20 const token = options.token
21 const now = new Date()
22 now.setTime(now.getTime() - 5000)
23
24 const createdAt = new Date(token.createdAt)
25
26 return { valid: createdAt.getTime() >= now.getTime() }
27 }
28
29 return { valid: true }
30 },
31
7fed6375
C
32 login (body) {
33 if (body.id === 'laguna' && body.password === 'laguna password') {
34 return Promise.resolve({
35 username: 'laguna',
36 email: 'laguna@example.com'
37 })
38 }
39
40 return null
41 }
42 })
43}
44
45async function unregister () {
46 return
47}
48
49module.exports = {
50 register,
51 unregister
52}
53
54// ###########################################################################