diff --git a/src/projects/extension/authorization/authorization.helper.ts b/src/projects/extension/authorization/authorization.helper.ts index 0d40642ff..2266d404c 100644 --- a/src/projects/extension/authorization/authorization.helper.ts +++ b/src/projects/extension/authorization/authorization.helper.ts @@ -50,6 +50,7 @@ export class AuthorizationHelper { const settings = workspaceFolder.settings; const key = this.createKey(settings); + const state = await this.resolveAuthenticationState(settings, key); const result = !state.isLoggedIn ? await this.authorize(settings.connection, state.loginUrl as string) @@ -79,7 +80,7 @@ export class AuthorizationHelper { return new Promise((resolve) => { const session = ConnectionHelper.createSession({...settings.connection, cookies}); session.on("traffic:received", (response) => { - if (response.method === "OnAuthenticationInformation") { + if (response.method === "OnAuthenticationInformation" || response.method === "OnConnected") { /** * remove all listeners so we dont have a memory leak * method exists but not in typings so cast this one to any @@ -140,6 +141,10 @@ export class AuthorizationHelper { strategyConstructor = await (await import("./form-strategy")).default as AuthorizationStrategyConstructor; break; + case AuthStrategy.NONE: + strategyConstructor = await (await import("./no-authorization-strategy")).default as AuthorizationStrategyConstructor; + break; + case AuthStrategy.CERTIFICATE: break; diff --git a/src/projects/extension/authorization/no-authorization-strategy.ts b/src/projects/extension/authorization/no-authorization-strategy.ts new file mode 100644 index 000000000..70710e3ac --- /dev/null +++ b/src/projects/extension/authorization/no-authorization-strategy.ts @@ -0,0 +1,13 @@ +import { AuthorizationStrategy, AuthorizationResult } from "@core/authorization"; + +export class NoneAuthorizationStrategy extends AuthorizationStrategy { + + public run(): Promise { + return Promise.resolve({ + success: true, + cookies: [] + }); + } +} + +export default NoneAuthorizationStrategy; diff --git a/src/projects/media/webview/projects/connection/src/app/data/api.ts b/src/projects/media/webview/projects/connection/src/app/data/api.ts index 4cbca1aed..3b2fae7c0 100644 --- a/src/projects/media/webview/projects/connection/src/app/data/api.ts +++ b/src/projects/media/webview/projects/connection/src/app/data/api.ts @@ -1,7 +1,8 @@ export enum AuthorizationStrategy { CERTIFICATE, FORM, - CUSTOM + CUSTOM, + NONE } /** diff --git a/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.html b/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.html index af305affe..791aac5d3 100644 --- a/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.html +++ b/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.html @@ -84,21 +84,9 @@

Authorization Settings

- -
- -

- custom strategy -

- -

- CERTIFICATE -

- - - - -
+ + + diff --git a/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.ts b/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.ts index 2aa08b238..2caf2d2ba 100644 --- a/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.ts +++ b/src/projects/media/webview/projects/connection/src/app/ui/edit/edit.ts @@ -22,6 +22,8 @@ export class ConnectionEditComponent implements OnInit, OnDestroy { */ public authorizationStrategy = AuthorizationStrategy; + public currentAuthorizationStrategy: AuthorizationStrategy = AuthorizationStrategy.FORM; + /** * form control for authorization strategy */ @@ -97,6 +99,7 @@ export class ConnectionEditComponent implements OnInit, OnDestroy { this.connectionFormHelper.save() .pipe(takeUntil(this.destroy$)) .subscribe((connection) => { + console.dir(connection); this.save.emit(connection) }); } @@ -127,13 +130,16 @@ export class ConnectionEditComponent implements OnInit, OnDestroy { * initialize authorization strategy form */ private initAuthorizationStrategyCtrl() { - this.authorizationStrategyCtrl = this.formbuilder.control(AuthorizationStrategy.FORM); + + this.currentAuthorizationStrategy = this.workspaceFolderSetting?.connection.authorization.strategy || AuthorizationStrategy.FORM; + this.authorizationStrategyCtrl = this.formbuilder.control(this.currentAuthorizationStrategy); /** register on value changes to update strategy */ this.authorizationStrategyCtrl.valueChanges .pipe(takeUntil(this.destroy$)) - .subscribe((value) => { - this.workspaceFolderSetting.connection.authorization.strategy = value; + .subscribe((value: string) => { + this.currentAuthorizationStrategy = parseInt(value, 10); + this.workspaceFolderSetting.connection.authorization.strategy = this.currentAuthorizationStrategy; }); } @@ -178,6 +184,9 @@ export class ConnectionEditComponent implements OnInit, OnDestroy { return Object.assign({}, connection, { label: this.connectionForm.controls.nameCtrl.value, connection: { + authorization: { + strategy: this.currentAuthorizationStrategy + }, host: this.connectionForm.controls.hostCtrl.value, port: this.connectionForm.controls.portCtrl.value, path: this.connectionForm.controls.pathCtrl.value, diff --git a/src/projects/media/webview/projects/connection/src/app/ui/strategy/form.ts b/src/projects/media/webview/projects/connection/src/app/ui/strategy/form.ts index cf1c3b3d8..52d5101dc 100644 --- a/src/projects/media/webview/projects/connection/src/app/ui/strategy/form.ts +++ b/src/projects/media/webview/projects/connection/src/app/ui/strategy/form.ts @@ -1,7 +1,7 @@ import { Component, OnInit, OnDestroy } from "@angular/core"; import { FormBuilder, FormControl } from "@angular/forms"; import { ConnectionFormHelper, BeforeSaveHook } from "../../utils/connection-form.helper"; -import { WorkspaceFolderSetting, AuthorizationStrategy } from "../../data/api"; +import { WorkspaceFolderSetting } from "../../data/api"; import { Subject } from "rxjs"; import { takeUntil } from "rxjs/operators"; @@ -69,15 +69,15 @@ export class FormStrategyComponent implements OnInit, OnDestroy { * create patch for authorization settings */ private createPatch(settings: WorkspaceFolderSetting): WorkspaceFolderSetting { - - settings.connection.authorization = { - strategy: AuthorizationStrategy.FORM, - data: { - domain: this.domainCtrl.value, - password: this.passwordCtrl.value, + settings.connection.authorization = Object.assign({}, + settings.connection.authorization, + { + data: { + domain: this.domainCtrl.value, + password: this.passwordCtrl.value, + } } - }; - + ); return settings; } diff --git a/src/projects/shared/authorization/api/index.ts b/src/projects/shared/authorization/api/index.ts index fdcacdb7d..2bb20e425 100644 --- a/src/projects/shared/authorization/api/index.ts +++ b/src/projects/shared/authorization/api/index.ts @@ -1,7 +1,8 @@ export enum AuthStrategy { CERTIFICATE, FORM, - CUSTOM + CUSTOM, + NONE } export interface AuthorizationData { diff --git a/src/projects/shared/connection/utils/connection.helper.ts b/src/projects/shared/connection/utils/connection.helper.ts index 0d50bf9f3..a3af81b96 100644 --- a/src/projects/shared/connection/utils/connection.helper.ts +++ b/src/projects/shared/connection/utils/connection.helper.ts @@ -57,6 +57,7 @@ export abstract class ConnectionHelper { rejectUnauthorized: !data.allowUntrusted, headers }); + return ws; }