aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-24 11:33:01 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commite307e4fce39853d445d086f92b8c556c363ee15d (patch)
tree0f3faaf3c73222db0fb55b72260c787aeeeb05eb /shared
parente1c5503114deef954731904695cd40dccfcef555 (diff)
downloadPeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.tar.gz
PeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.tar.zst
PeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.zip
Add ability for auth plugins to hook tokens validity
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/users/login.ts19
-rw-r--r--shared/models/activitypub/context.ts1
-rw-r--r--shared/models/plugins/register-server-auth.model.ts8
-rw-r--r--shared/models/server/job.model.ts2
4 files changed, 28 insertions, 2 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts
index 2d68337a6..b12b51b8c 100644
--- a/shared/extra-utils/users/login.ts
+++ b/shared/extra-utils/users/login.ts
@@ -43,6 +43,24 @@ async function serverLogin (server: Server) {
43 return res.body.access_token as string 43 return res.body.access_token as string
44} 44}
45 45
46function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) {
47 const path = '/api/v1/users/token'
48
49 const body = {
50 client_id: server.client.id,
51 client_secret: server.client.secret,
52 refresh_token: refreshToken,
53 response_type: 'code',
54 grant_type: 'refresh_token'
55 }
56
57 return request(server.url)
58 .post(path)
59 .type('form')
60 .send(body)
61 .expect(expectedStatus)
62}
63
46async function userLogin (server: Server, user: User, expectedStatus = 200) { 64async function userLogin (server: Server, user: User, expectedStatus = 200) {
47 const res = await login(server.url, server.client, user, expectedStatus) 65 const res = await login(server.url, server.client, user, expectedStatus)
48 66
@@ -83,6 +101,7 @@ export {
83 login, 101 login,
84 logout, 102 logout,
85 serverLogin, 103 serverLogin,
104 refreshToken,
86 userLogin, 105 userLogin,
87 getAccessToken, 106 getAccessToken,
88 setAccessTokensToServers, 107 setAccessTokensToServers,
diff --git a/shared/models/activitypub/context.ts b/shared/models/activitypub/context.ts
new file mode 100644
index 000000000..bd795a2fd
--- /dev/null
+++ b/shared/models/activitypub/context.ts
@@ -0,0 +1 @@
export type ContextType = 'All' | 'View' | 'Announce' | 'CacheFile'
diff --git a/shared/models/plugins/register-server-auth.model.ts b/shared/models/plugins/register-server-auth.model.ts
index dc46dcbc8..403a49994 100644
--- a/shared/models/plugins/register-server-auth.model.ts
+++ b/shared/models/plugins/register-server-auth.model.ts
@@ -1,4 +1,5 @@
1import { UserRole } from '@shared/models' 1import { UserRole } from '@shared/models'
2import { MOAuthToken } from '@server/typings/models'
2 3
3export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions 4export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
4 5
@@ -6,11 +7,16 @@ export interface RegisterServerAuthPassOptions {
6 // Authentication name (a plugin can register multiple auth strategies) 7 // Authentication name (a plugin can register multiple auth strategies)
7 authName: string 8 authName: string
8 9
9 onLogout?: Function 10 // Called by PeerTube when a user from your plugin logged out
11 onLogout?(): void
10 12
11 // Weight of this authentication so PeerTube tries the auth methods in DESC weight order 13 // Weight of this authentication so PeerTube tries the auth methods in DESC weight order
12 getWeight(): number 14 getWeight(): number
13 15
16 // Your plugin can hook PeerTube access/refresh token validity
17 // So you can control for your plugin the user session lifetime
18 hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }>
19
14 // Used by PeerTube to login a user 20 // Used by PeerTube to login a user
15 // Returns null if the login failed, or { username, email } on success 21 // Returns null if the login failed, or { username, email } on success
16 login(body: { 22 login(body: {
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts
index 694361276..57d61c480 100644
--- a/shared/models/server/job.model.ts
+++ b/shared/models/server/job.model.ts
@@ -1,6 +1,6 @@
1import { ContextType } from '@server/helpers/activitypub'
2import { SendEmailOptions } from './emailer.model' 1import { SendEmailOptions } from './emailer.model'
3import { VideoResolution } from '@shared/models' 2import { VideoResolution } from '@shared/models'
3import { ContextType } from '../activitypub/context'
4 4
5export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' 5export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed'
6 6