Skip to content

Commit 6f1bf6b

Browse files
committed
Merge branch 'mh/credential-oauth-refresh-token' into seen
The credential subsystem learns to help OAuth framework. * mh/credential-oauth-refresh-token: credential: new attribute oauth_refresh_token
2 parents 49ee2c2 + e4f5c19 commit 6f1bf6b

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

Documentation/git-credential.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ Git understands the following attributes:
156156
When reading credentials from helpers, `git credential fill` ignores expired
157157
passwords. Represented as Unix time UTC, seconds since 1970.
158158

159+
`oauth_refresh_token`::
160+
161+
An OAuth refresh token may accompany a password that is an OAuth access
162+
token. Helpers must treat this attribute as confidential like the password
163+
attribute. Git itself has no special behaviour for this attribute.
164+
159165
`url`::
160166

161167
When this special attribute is read by `git credential`, the

builtin/credential-cache--daemon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ static void serve_one_client(FILE *in, FILE *out)
131131
if (e->item.password_expiry_utc != TIME_MAX)
132132
fprintf(out, "password_expiry_utc=%"PRItime"\n",
133133
e->item.password_expiry_utc);
134+
if (e->item.oauth_refresh_token)
135+
fprintf(out, "oauth_refresh_token=%s\n",
136+
e->item.oauth_refresh_token);
134137
}
135138
}
136139
else if (!strcmp(action.buf, "exit")) {

credential.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void credential_clear(struct credential *c)
2222
free(c->path);
2323
free(c->username);
2424
free(c->password);
25+
free(c->oauth_refresh_token);
2526
string_list_clear(&c->helpers, 0);
2627
strvec_clear(&c->wwwauth_headers);
2728

@@ -241,6 +242,9 @@ int credential_read(struct credential *c, FILE *fp)
241242
c->password_expiry_utc = parse_timestamp(value, NULL, 10);
242243
if (c->password_expiry_utc == 0 || errno == ERANGE)
243244
c->password_expiry_utc = TIME_MAX;
245+
} else if (!strcmp(key, "oauth_refresh_token")) {
246+
free(c->oauth_refresh_token);
247+
c->oauth_refresh_token = xstrdup(value);
244248
} else if (!strcmp(key, "url")) {
245249
credential_from_url(c, value);
246250
} else if (!strcmp(key, "quit")) {
@@ -276,6 +280,7 @@ void credential_write(const struct credential *c, FILE *fp)
276280
credential_write_item(fp, "path", c->path, 0);
277281
credential_write_item(fp, "username", c->username, 0);
278282
credential_write_item(fp, "password", c->password, 0);
283+
credential_write_item(fp, "oauth_refresh_token", c->oauth_refresh_token, 0);
279284
if (c->password_expiry_utc != TIME_MAX) {
280285
char *s = xstrfmt("%"PRItime, c->password_expiry_utc);
281286
credential_write_item(fp, "password_expiry_utc", s, 0);
@@ -401,6 +406,7 @@ void credential_reject(struct credential *c)
401406

402407
FREE_AND_NULL(c->username);
403408
FREE_AND_NULL(c->password);
409+
FREE_AND_NULL(c->oauth_refresh_token);
404410
c->password_expiry_utc = TIME_MAX;
405411
c->approved = 0;
406412
}

credential.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct credential {
141141
char *protocol;
142142
char *host;
143143
char *path;
144+
char *oauth_refresh_token;
144145
timestamp_t password_expiry_utc;
145146
};
146147

t/t0300-credentials.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ test_expect_success 'credential_approve stores password expiry' '
214214
EOF
215215
'
216216

217+
test_expect_success 'credential_approve stores oauth refresh token' '
218+
check approve useless <<-\EOF
219+
protocol=http
220+
host=example.com
221+
username=foo
222+
password=bar
223+
oauth_refresh_token=xyzzy
224+
--
225+
--
226+
useless: store
227+
useless: protocol=http
228+
useless: host=example.com
229+
useless: username=foo
230+
useless: password=bar
231+
useless: oauth_refresh_token=xyzzy
232+
EOF
233+
'
234+
217235
test_expect_success 'do not bother storing password-less credential' '
218236
check approve useless <<-\EOF
219237
protocol=http

0 commit comments

Comments
 (0)