]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/plugins/register-server-auth.model.ts
403a499946bf2c221d11b1c2d556ecac9645923d
[github/Chocobozzz/PeerTube.git] / shared / models / plugins / register-server-auth.model.ts
1 import { UserRole } from '@shared/models'
2 import { MOAuthToken } from '@server/typings/models'
3
4 export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
5
6 export interface RegisterServerAuthPassOptions {
7 // Authentication name (a plugin can register multiple auth strategies)
8 authName: string
9
10 // Called by PeerTube when a user from your plugin logged out
11 onLogout?(): void
12
13 // Weight of this authentication so PeerTube tries the auth methods in DESC weight order
14 getWeight(): number
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
20 // Used by PeerTube to login a user
21 // Returns null if the login failed, or { username, email } on success
22 login(body: {
23 id: string
24 password: string
25 }): Promise<{
26 username: string
27 email: string
28 role?: UserRole
29 displayName?: string
30 } | null>
31 }
32
33 export interface RegisterServerAuthExternalOptions {
34 // Authentication name (a plugin can register multiple auth strategies)
35 authName: string
36
37 onLogout?: Function
38 }
39
40 export interface RegisterServerAuthExternalResult {
41 onAuth (options: { username: string, email: string }): void
42 }