From 7fed637506043e4432cbebe041ada0625171cceb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Apr 2020 16:07:04 +0200 Subject: Begin auth plugin support --- shared/extra-utils/users/login.ts | 11 ++++++++ .../models/plugins/register-server-auth.model.ts | 33 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 shared/models/plugins/register-server-auth.model.ts (limited to 'shared') diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index 4fe54a74a..2d68337a6 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts @@ -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, diff --git a/shared/models/plugins/register-server-auth.model.ts b/shared/models/plugins/register-server-auth.model.ts new file mode 100644 index 000000000..34ebbe712 --- /dev/null +++ b/shared/models/plugins/register-server-auth.model.ts @@ -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 +} -- cgit v1.2.3