Begin auth plugin support

This commit is contained in:
Chocobozzz
2020-04-22 16:07:04 +02:00
committed by Chocobozzz
parent 8d41976378
commit 7fed637506
23 changed files with 604 additions and 74 deletions

View File

@@ -27,6 +27,16 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) {
.expect(expectedStatus)
}
function logout (url: string, token: string, expectedStatus = 200) {
const path = '/api/v1/users/revoke-token'
return request(url)
.post(path)
.set('Authorization', 'Bearer ' + token)
.type('form')
.expect(expectedStatus)
}
async function serverLogin (server: Server) {
const res = await login(server.url, server.client, server.user, 200)
@@ -71,6 +81,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) {
export {
login,
logout,
serverLogin,
userLogin,
getAccessToken,

View File

@@ -0,0 +1,33 @@
import { UserRole } from '@shared/models'
export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
export interface RegisterServerAuthPassOptions {
type: 'id-and-pass'
onLogout?: Function
getWeight(): number
// 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 {
type: 'external'
onLogout?: Function
}
export interface RegisterServerAuthExternalResult {
onAuth (options: { username: string, email: string }): void
}