From 4a8d113b9b57d97ff13ad1608798eabca99643e4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 Apr 2020 14:49:03 +0200 Subject: Begin support for external auths --- .eslintrc.json | 1 + client/src/app/core/auth/auth.service.ts | 4 +- client/src/app/core/server/server.service.ts | 4 +- client/src/app/login/login.component.html | 88 ++++---- client/src/app/login/login.component.ts | 36 +++- server/controllers/api/config.ts | 56 ++++- server/controllers/plugins.ts | 20 +- server/lib/auth.ts | 225 +++++++++++++++------ server/lib/oauth-model.ts | 2 +- server/lib/plugins/register-helpers-store.ts | 42 ++-- server/middlewares/validators/plugins.ts | 25 ++- server/typings/express.ts | 3 + .../models/plugins/register-server-auth.model.ts | 40 ++-- .../plugins/register-server-setting.model.ts | 2 +- shared/models/server/server-config.model.ts | 16 ++ 15 files changed, 393 insertions(+), 171 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9b578b186..e71be9bc5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -83,6 +83,7 @@ "@typescript-eslint/consistent-type-definitions": "off", "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/no-extraneous-class": "off", // bugged but useful "@typescript-eslint/restrict-plus-operands": "off" diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 9ae008e39..61d755ba0 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -145,7 +145,7 @@ export class AuthService { return !!this.getAccessToken() } - login (username: string, password: string) { + login (username: string, password: string, token?: string) { // Form url encoded const body = { client_id: this.clientId, @@ -157,6 +157,8 @@ export class AuthService { password } + if (token) Object.assign(body, { externalAuthToken: token }) + const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') return this.http.post(AuthService.BASE_TOKEN_URL, objectToUrlEncoded(body), { headers }) .pipe( diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index da7832b32..eac8f85e4 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -54,7 +54,9 @@ export class ServerService { } }, plugin: { - registered: [] + registered: [], + registeredExternalAuths: [], + registeredIdAndPassAuths: [] }, theme: { registered: [], diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html index 3a2d4b876..3e53e5854 100644 --- a/client/src/app/login/login.component.html +++ b/client/src/app/login/login.component.html @@ -3,59 +3,61 @@ Login -