2020-04-22 14:07:04 +00:00
|
|
|
import { UserRole } from '@shared/models'
|
2020-04-24 09:33:01 +00:00
|
|
|
import { MOAuthToken } from '@server/typings/models'
|
2020-04-22 14:07:04 +00:00
|
|
|
|
|
|
|
export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
|
|
|
|
|
|
|
|
export interface RegisterServerAuthPassOptions {
|
2020-04-23 09:36:50 +00:00
|
|
|
// Authentication name (a plugin can register multiple auth strategies)
|
|
|
|
authName: string
|
2020-04-22 14:07:04 +00:00
|
|
|
|
2020-04-24 09:33:01 +00:00
|
|
|
// Called by PeerTube when a user from your plugin logged out
|
|
|
|
onLogout?(): void
|
2020-04-22 14:07:04 +00:00
|
|
|
|
2020-04-23 09:36:50 +00:00
|
|
|
// Weight of this authentication so PeerTube tries the auth methods in DESC weight order
|
2020-04-22 14:07:04 +00:00
|
|
|
getWeight(): number
|
|
|
|
|
2020-04-24 09:33:01 +00:00
|
|
|
// Your plugin can hook PeerTube access/refresh token validity
|
|
|
|
// So you can control for your plugin the user session lifetime
|
|
|
|
hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }>
|
|
|
|
|
2020-04-22 14:07:04 +00:00
|
|
|
// Used by PeerTube to login a user
|
|
|
|
// Returns null if the login failed, or { username, email } on success
|
|
|
|
login(body: {
|
|
|
|
id: string
|
|
|
|
password: string
|
|
|
|
}): Promise<{
|
|
|
|
username: string
|
|
|
|
email: string
|
|
|
|
role?: UserRole
|
|
|
|
displayName?: string
|
|
|
|
} | null>
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RegisterServerAuthExternalOptions {
|
2020-04-23 09:36:50 +00:00
|
|
|
// Authentication name (a plugin can register multiple auth strategies)
|
|
|
|
authName: string
|
2020-04-22 14:07:04 +00:00
|
|
|
|
|
|
|
onLogout?: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RegisterServerAuthExternalResult {
|
|
|
|
onAuth (options: { username: string, email: string }): void
|
|
|
|
}
|