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 support to extract and use basic auth username and password from RPC URL #9

Closed
hboon opened this issue Aug 21, 2020 · 0 comments · Fixed by #10
Closed

Add support to extract and use basic auth username and password from RPC URL #9

hboon opened this issue Aug 21, 2020 · 0 comments · Fixed by #10
Assignees

Comments

@hboon
Copy link
Member

hboon commented Aug 21, 2020

Add support to extract and use basic auth username and password from RPC URL.

Replace:

engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl)))

with:

    let username, password;
    let start = rpcUrl.indexOf("://");
    if (start != -1) {
      start += 3;
      const end = rpcUrl.indexOf("@", start + 1);
      if (end != -1) {
        const credentials = rpcUrl.substring(start, end);
        let [u, p] = credentials.split(":");
        username = u;
        password = p;
      }
    }
    if (typeof username === 'undefined' || typeof password === 'undefined') {
        engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl)))
    } else {
        engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl,0,username,password)))
    }

And minify :)

@hboon hboon closed this as completed in #10 Aug 21, 2020
hboon added a commit that referenced this issue Aug 21, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…vider

allow credentials in http provider #9
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

Successfully merging a pull request may close this issue.

2 participants