]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'mh/credential-oauth-refresh-token-with-wincred'
authorJunio C Hamano <gitster@pobox.com>
Thu, 8 Feb 2024 21:20:34 +0000 (13:20 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Feb 2024 21:20:34 +0000 (13:20 -0800)
The wincred credential backend has been taught to support oauth refresh
token the same way as credential-cache and credential-libsecret backends.

* mh/credential-oauth-refresh-token-with-wincred:
  credential/wincred: store oauth_refresh_token

1  2 
contrib/credential/wincred/git-credential-wincred.c

index 4cd56c42e24469a48a40e7b02de4b4921ff8662c,f8968ec8648c9dfec1ecf614b4131aa7205a2504..4be0d58cd89ad7bfbbf8c8fc0b2268cee9052f9e
@@@ -146,12 -139,27 +151,27 @@@ static void get_credential(void
  
        /* search for the first credential that matches username */
        for (i = 0; i < num_creds; ++i)
 -              if (match_cred(creds[i])) {
 +              if (match_cred(creds[i], 0)) {
                        write_item("username", creds[i]->UserName,
                                creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
-                       write_item("password",
-                               (LPCWSTR)creds[i]->CredentialBlob,
-                               creds[i]->CredentialBlobSize / sizeof(WCHAR));
+                       if (creds[i]->CredentialBlobSize > 0) {
+                               secret = xmalloc(creds[i]->CredentialBlobSize);
+                               wcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));
+                               line = wcstok_s(secret, L"\r\n", &remaining_lines);
+                               write_item("password", line, line ? wcslen(line) : 0);
+                               while(line != NULL) {
+                                       part = wcstok_s(line, L"=", &remaining_parts);
+                                       if (!wcscmp(part, L"oauth_refresh_token")) {
+                                               write_item("oauth_refresh_token", remaining_parts, remaining_parts ? wcslen(remaining_parts) : 0);
+                                       }
+                                       line = wcstok_s(NULL, L"\r\n", &remaining_lines);
+                               }
+                               free(secret);
+                       } else {
+                               write_item("password",
+                                               (LPCWSTR)creds[i]->CredentialBlob,
+                                               creds[i]->CredentialBlobSize / sizeof(WCHAR));
+                       }
                        for (int j = 0; j < creds[i]->AttributeCount; j++) {
                                attr = creds[i]->Attributes + j;
                                if (!wcscmp(attr->Keyword, L"git_password_expiry_utc")) {