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

deno run with basic authentication #5897

Closed
max-pub opened this issue May 27, 2020 · 8 comments
Closed

deno run with basic authentication #5897

max-pub opened this issue May 27, 2020 · 8 comments
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted)

Comments

@max-pub
Copy link

max-pub commented May 27, 2020

Please support basic authentication for "deno run" like

deno run https://USER:PASS@xxxx.com/yyyyy.ts
@ry ry added cli related to cli/ dir feat new feature (which has been agreed to/accepted) labels May 27, 2020
@ry
Copy link
Member

ry commented May 27, 2020

Yes we should support this. Not a high priority for me, but I'd be happy to lend some guidance to anyone who wanted to add this.

@tumile
Copy link
Contributor

tumile commented May 27, 2020

Hi @ry I can work on this, please let me know where to start.

@jakajancar
Copy link

Would you then expect that imports also contain username/pass?

Or would the username/pass from the root script magically apply to all imports with the same host (quasi "logged in")?

Or would it work only for single-file scripts?

#1 and #2 seem pretty weird to me. #3 seems clean, though not sure if still useful to people.

@Yamboy1
Copy link

Yamboy1 commented May 28, 2020

For imports, especially as basic authentication isn't available all the time, think local urls, it seems like a decent idea to add a cli option for this, or preferably a path to a file with credentials similar to ssh -i ~/.ssh/identity_file. Either this or environment variables seems plausable as well. These credentials would also work for accessing the original file if you're trying to run a file such as the original example: deno run https://xxxx.com/yyyyy.ts -i ~/.deno/identity or something like that.

@tumile
Copy link
Contributor

tumile commented May 29, 2020

Looks like Deno's underlying HTTP client reqwest already allows basic authentication. In the method to fetch remote source

pub fn fetch_once(
  client: Client,
  url: &Url,  // url: http://user:pass@52.90.21.56/welcome.ts
  cached_etag: Option<String>,
) -> ... {
  ...
  let mut request = client.get(url.clone());
  // request: RequestBuilder { method: GET, url: "http://52.90.21.56/welcome.ts", headers: {"authorization": "Basic dXNlcjpwYXNz"} }
  ...
}

Username and password are automatically extracted from URL and set to header. I put up a simple basic auth example, try this:

deno run http://user:pass@52.90.21.56/welcome.ts
import * as script from "http://user:pass@52.90.21.56/welcome.ts";
script;

@max-pub
Copy link
Author

max-pub commented Jun 2, 2020

I have to apologize. I was using git clone https://user:pass@local.gitlab.com which was working fine, so I expected basic auth behind the scenes.
Trying to run the project directly from the repository didnt work with deno.
Your example runs just fine.
git seems to to use another authentication method here.

@jerrygreen
Copy link

jerrygreen commented Nov 13, 2020

If you're going to make an implementation, please consider this suggestion: #5239 (comment)

Would be absolutely cool to hear feedback from Ryan (I suspect he loves curl as much as I do, and would like the idea)

@bartlomieju
Copy link
Member

This is now supported using DENO_AUTH_TOKENS env variable: https://deno.land/manual@v1.11.2/linking_to_external_code/private#deno_auth_tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted)
Projects
None yet
Development

No branches or pull requests

7 participants