]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - 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
index c0e560019c59e5951d25a4457b39057126e472a5..ceab7b60de3a96284e0ed688aaac6b9b2da9aebf 100644 (file)
@@ -11,6 +11,24 @@ async function register ({
 
     getWeight: () => 30,
 
+    hookTokenValidity: (options) => {
+      if (options.type === 'refresh') {
+        return { valid: false }
+      }
+
+      if (options.type === 'access') {
+        const token = options.token
+        const now = new Date()
+        now.setTime(now.getTime() - 5000)
+
+        const createdAt = new Date(token.createdAt)
+
+        return { valid: createdAt.getTime() >= now.getTime() }
+      }
+
+      return { valid: true }
+    },
+
     login (body) {
       if (body.id === 'laguna' && body.password === 'laguna password') {
         return Promise.resolve({