-
Notifications
You must be signed in to change notification settings - Fork 98
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
Support for bearer auth in .netrc #267
Conversation
Previously the .netrc only handled authorization that contains both a username and password. This is a divergence from the behavior of httpie. This only activates when `--auth-type bearer` is specified without the `--auth` flag, so I believe it should be a compatible change.
fcb8c40
to
eac4259
Compare
force-pushed to squash rustfmt fixes into the commits |
Thanks, @porglezomp. Can I double check which version of HTTPie was the
|
This is specifically different behavior from httpie. I don't know how strict you're interested in the compatibility between xh and httpie being. This enhancement doesn't change behavior on any httpie command that currently works:
This does cause xh to handle a new case. |
I am okay with supporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using netrc for this feels like a stretch, but I can't think of any failure scenarios or obviously better alternatives, so I think supporting this is for the best.
(We can't extend the format with a token
directive, Python's netrc parser doesn't like that.)
In httpie/cli#1216 Jakub actually suggested this enhancement, so it's worth trying there as well, so I think it would be accepted in HTTPie.
@@ -438,13 +448,20 @@ mod tests { | |||
notfound(STRANGE_CHARACTERS, COM); | |||
} | |||
|
|||
fn found(netrc: &str, host: url::Host<&str>, login: &str, password: &str) { | |||
#[track_caller] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about that attribute, this is great
An optional login field seems fine as long as it's only optional for bearer auth, and when the password is a token there's no good value for login. So I think it's better this way. Though HTTPie crashes if there's no login:
|
@blyxxyz What if we require the login field to equal |
That's a little unintuitive, I think we should ideally do it in a way that could be guessed without documentation. For databricks it's a hack to fit it into curl's existing netrc loader, but we're providing the netrc loader so we have more options. Is there a drawback to an optional login field? It made me uneasy at first but after thinking through it it seems well-behaved. |
Sounds reasonable. Let's keep the login field optional 👍. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Are you interested in pitching this to HTTPie?
My work situation means I'd need to get approval for that as a separate contribution, so I'm probably not the best person to pitch that at the moment 😔 |
Pitched: httpie/cli#1569 |
Previously the
.netrc
only handled authorization that contains both a username and password.This is a divergence from the behavior of httpie.
This only activates when
--auth-type bearer
is specified without the--auth
flag, so I believe it should be a compatible change. (I believe previously using it like this would have always reported an error?)