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

Parameters "ssl" and "authtype" do not work #2

Open
jonpfote opened this issue May 13, 2023 · 0 comments
Open

Parameters "ssl" and "authtype" do not work #2

jonpfote opened this issue May 13, 2023 · 0 comments

Comments

@jonpfote
Copy link

Hello,
I noticed that the parameters "ssl" and "authtype" currently do not work.

The current code (which has the bug) can be found here: https://github.com/vscode-lcode/webdav/blob/main/lib/webdav.js#L180-L236

Please change the implementation of getClient in lib/webdav.js to the following code:

  getClient(uri) {
    const searchParams = new URLSearchParams(uri.query)


    // ssl
    let protocol = "http://"
    if (["", "true", "1"].indexOf(searchParams.get("ssl")) > -1) {
      protocol = "https://";
    }

    // connection already established
    const key = protocol + uri.authority;
    if (this.clients[key]) {
      return this.clients[key];
    }

    /**@type {webdav.WebDAVClientOptions} */
    const opt = {};

    // auth
    if (
      uri.authority.indexOf("@") >= 0
      && uri.authority.indexOf(":") >= 0
      && uri.authority.indexOf(":") < uri.authority.indexOf("@")
      && searchParams.has("authtype")
    ) {
      const authtype = searchParams.get("authtype");
      const [username, password] = (uri.authority.split("@")[0]).split(":")
      switch (authtype) {
        case "":
        case "b":
        case "basic":
          opt.authType = webdav.AuthType.Password;
          opt.username = username;
          opt.password = password;
          break;

        case "d":
        case "digest":
          opt.authType = webdav.AuthType.Digest;
          opt.username = username;
          opt.password = password;
          break;

        default:
          throw new Error(
            `Authentication type '${authtype}' is not supported!`
          );
      }
    }

    let client = webdav.createClient(key, opt);
    this.clients[key] = client;
    return client;
  }
}

This means that getOriginWithAuth can be removed as my implementation does not use it.
https://github.com/vscode-lcode/webdav/blob/main/lib/webdav.js#L180-L236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant