From 9fbc7e627d1d1f0125400d9915df5b0208cb8c56 Mon Sep 17 00:00:00 2001 From: Simon Bin Date: Wed, 14 Dec 2022 12:54:59 +0100 Subject: [PATCH] add a new checkbox to the yasgui settings, allow using password protected endpoint --- packages/yasgui/src/TabPanel.ts | 34 ++++++++++++++++++++++++++++++++ packages/yasgui/src/index.ts | 1 + packages/yasgui/src/linkUtils.ts | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/packages/yasgui/src/TabPanel.ts b/packages/yasgui/src/TabPanel.ts index dbcf7c5..30b5821 100644 --- a/packages/yasgui/src/TabPanel.ts +++ b/packages/yasgui/src/TabPanel.ts @@ -77,6 +77,11 @@ export default class TabPanel { // Draw Accept headers this.setAcceptHeader_select(reqConfig.acceptHeaderSelect); this.setAcceptHeader_graph(reqConfig.acceptHeaderGraph); + + if (typeof reqConfig.withCredentials !== "function") { + this.setUseLogin(reqConfig.withCredentials); + } + // console.log('setting args',reqConfig.args) if (typeof reqConfig.args !== "function") { this.setArguments([...reqConfig.args] || []); @@ -194,6 +199,32 @@ export default class TabPanel { this.menuElement.appendChild(acceptWrapper); } + private setUseLogin!: (useLogin: boolean) => void; + private drawUseLoginInput() { + const useLoginWrapper = document.createElement("div"); + addClass(useLoginWrapper, "requestConfigWrapper"); + createLabel("Use browser login", useLoginWrapper); + + // Create Button + const checkbox = document.createElement("input"); + checkbox.type = "checkbox"; + if (this.tab.getRequestConfig().withCredentials) { + checkbox.checked = true; + } + + this.setUseLogin = (useLogin) => { + checkbox.checked = useLogin; + }; + checkbox.onclick = (ev) => { + this.tab.setRequestConfig({ withCredentials: checkbox.checked }); + ev.stopPropagation(); + }; + + // Add elements to container + useLoginWrapper.appendChild(checkbox); + this.menuElement.appendChild(useLoginWrapper); + } + private setArguments!: (args: TextInputPair[]) => void; private drawArgumentsInput() { const onBlur = () => { @@ -337,6 +368,9 @@ export default class TabPanel { // Draw request Method this.drawRequestMethodSelector(); + // Draw use login + this.drawUseLoginInput(); + // Draw Accept headers this.drawAcceptSelector(); diff --git a/packages/yasgui/src/index.ts b/packages/yasgui/src/index.ts index 0a98b24..74ded46 100644 --- a/packages/yasgui/src/index.ts +++ b/packages/yasgui/src/index.ts @@ -310,6 +310,7 @@ export class Yasgui extends EventEmitter { const currentTab = this.getTab(); if (currentTab) { tabConfig.requestConfig.endpoint = currentTab.getEndpoint(); + tabConfig.requestConfig.withCredentials = currentTab.getRequestConfig().withCredentials; } } if (opts.avoidDuplicateTabs) { diff --git a/packages/yasgui/src/linkUtils.ts b/packages/yasgui/src/linkUtils.ts index 00aff03..5132463 100644 --- a/packages/yasgui/src/linkUtils.ts +++ b/packages/yasgui/src/linkUtils.ts @@ -73,6 +73,7 @@ export function createShareLink(forUrl: string, tab: Tab) { export type ShareConfigObject = { query: string; endpoint: string; + useLogin: boolean; requestMethod: PlainRequestConfig["method"]; tabTitle: string; headers: PlainRequestConfig["headers"]; @@ -92,6 +93,7 @@ export function createShareConfig(tab: Tab): ShareConfigObject { return { query: tab.getQuery(), endpoint: tab.getEndpoint(), + useLogin: getAsValue(requestConfig.withCredentials, yasgui), requestMethod: getAsValue(requestConfig.method, yasgui), tabTitle: tab.getName(), // headers: isFunction(requestConfig.headers) ? requestConfig.headers(tab.yasgui) : requestConfig.headers, @@ -134,6 +136,8 @@ export function getConfigFromUrl(defaults: PersistedJson, _url?: string): Persis options.requestConfig.acceptHeaderSelect = value; } else if (key == "endpoint") { options.requestConfig.endpoint = value; + } else if (key == "useLogin") { + options.requestConfig.withCredentials = value === "true"; } else if (key == "requestMethod") { options.requestConfig.method = value; } else if (key == "tabTitle") {