Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new checkbox to the yasgui settings, allow using password protected endpoint #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/yasgui/src/TabPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export default class TabPanel {
// Draw Accept headers
this.setAcceptHeader_select(<string>reqConfig.acceptHeaderSelect);
this.setAcceptHeader_graph(<string>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] || []);
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -337,6 +368,9 @@ export default class TabPanel {
// Draw request Method
this.drawRequestMethodSelector();

// Draw use login
this.drawUseLoginInput();

// Draw Accept headers
this.drawAcceptSelector();

Expand Down
1 change: 1 addition & 0 deletions packages/yasgui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/yasgui/src/linkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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,
Expand Down Expand Up @@ -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 = <any>value;
} else if (key == "tabTitle") {
Expand Down