]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/users/login.ts
Add ability for auth plugins to hook tokens validity
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / login.ts
index 2d68337a6affd38f32b5243500d9cb8dc37da0d5..b12b51b8c54149f7826c1a481f6f42b8fc8885f4 100644 (file)
@@ -43,6 +43,24 @@ async function serverLogin (server: Server) {
   return res.body.access_token as string
 }
 
+function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) {
+  const path = '/api/v1/users/token'
+
+  const body = {
+    client_id: server.client.id,
+    client_secret: server.client.secret,
+    refresh_token: refreshToken,
+    response_type: 'code',
+    grant_type: 'refresh_token'
+  }
+
+  return request(server.url)
+    .post(path)
+    .type('form')
+    .send(body)
+    .expect(expectedStatus)
+}
+
 async function userLogin (server: Server, user: User, expectedStatus = 200) {
   const res = await login(server.url, server.client, user, expectedStatus)
 
@@ -83,6 +101,7 @@ export {
   login,
   logout,
   serverLogin,
+  refreshToken,
   userLogin,
   getAccessToken,
   setAccessTokensToServers,