credential: add WWW-Authenticate header to cred requests
Add the value of the WWW-Authenticate response header to credential
requests. Credential helpers that understand and support HTTP
authentication and authorization can use this standard header (RFC 2616
Section 14.47 [1]) to generate valid credentials.
WWW-Authenticate headers can contain information pertaining to the
authority, authentication mechanism, or extra parameters/scopes that are
required.
The current I/O format for credential helpers only allows for unique
names for properties/attributes, so in order to transmit multiple header
values (with a specific order) we introduce a new convention whereby a
C-style array syntax is used in the property name to denote multiple
ordered values for the same property.
In this case we send multiple `wwwauth[]` properties where the order
that the repeated attributes appear in the conversation reflects the
order that the WWW-Authenticate headers appeared in the HTTP response.
Add a set of tests to exercise the HTTP authentication header parsing
and the interop with credential helpers. Credential helpers will receive
WWW-Authenticate information in credential requests.
[1] https://datatracker.ietf.org/doc/html/rfc2616#section-14.47
Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthew John Cheetham committedFeb 27, 2023 at 17:20 UTC5f2117b24f568ecc789c677748d70ccd538b16ba
3 files changed+263-1
Documentation/git-credential.txt
+18-1
index ac2818b9f6..50759153ef 100644--- a/Documentation/git-credential.txt+++ b/Documentation/git-credential.txt@@ -113,7 +113,13 @@ separated by an `=` (equals) sign, followed by a newline. The key may contain any bytes except `=`, newline, or NUL. The value may contain any bytes except newline or NUL.-In both cases, all bytes are treated as-is (i.e., there is no quoting,+Attributes with keys that end with C-style array brackets `[]` can have+multiple values. Each instance of a multi-valued attribute forms an+ordered list of values - the order of the repeated attributes defines+the order of the values. An empty multi-valued attribute (`key[]=\n`)+acts to clear any previous entries and reset the list.++In all cases, all bytes are treated as-is (i.e., there is no quoting, and one cannot transmit a value with newline or NUL in it). The list of attributes is terminated by a blank line or end-of-file.@@ -160,6 +166,17 @@ empty string. Components which are missing from the URL (e.g., there is no username in the example above) will be left unset.+`wwwauth[]`::++ When an HTTP response is received by Git that includes one or more+ 'WWW-Authenticate' authentication headers, these will be passed by Git+ to credential helpers.+++Each 'WWW-Authenticate' header value is passed as a multi-valued+attribute 'wwwauth[]', where the order of the attributes is the same as+they appear in the HTTP response. This attribute is 'one-way' from Git+to pass additional information to credential helpers.+ Unrecognised attributes are silently discarded. GIT
credential.c
+3
index 897b467933..f566c8ab19 100644--- a/credential.c+++ b/credential.c@@ -270,6 +270,9 @@ void credential_write(const struct credential *c, FILE *fp) credential_write_item(fp, "path", c->path, 0); credential_write_item(fp, "username", c->username, 0); credential_write_item(fp, "password", c->password, 0);+ for (size_t i = 0; i < c->wwwauth_headers.nr; i++)+ credential_write_item(fp, "wwwauth[]", c->wwwauth_headers.v[i],+ 0); } static int run_credential_helper(struct credential *c,