|
8 | 8 | # include <emscripten.h> |
9 | 9 |
|
10 | 10 | # include "../utils/common.hpp" |
| 11 | +# include "../utils/credentials.hpp" |
11 | 12 | # include "constants.hpp" |
12 | 13 | # include "read_buffer.hpp" |
13 | 14 | # include "response.hpp" |
@@ -464,28 +465,38 @@ static int create_credential(wasm_http_stream* stream) |
464 | 465 | } |
465 | 466 | subtransport->m_authorization_header = ""; |
466 | 467 |
|
467 | | - // Check that response headers show support for 'www-authenticate: Basic'. |
468 | | - if (!stream->m_response.has_header_starts_with("www-authenticate", "Basic")) |
| 468 | + if (!want_user_credentials()) |
469 | 469 | { |
470 | | - git_error_set( |
471 | | - GIT_ERROR_HTTP, |
472 | | - "remote host for request %s does not support Basic authentication", |
473 | | - stream->m_unconverted_url.c_str() |
474 | | - ); |
475 | | - return -1; |
| 470 | + // Check that response headers show support for 'www-authenticate: Basic'. |
| 471 | + if (!stream->m_response.has_header_starts_with("www-authenticate", "Basic")) |
| 472 | + { |
| 473 | + git_error_set( |
| 474 | + GIT_ERROR_HTTP, |
| 475 | + "remote host for request %s does not support Basic authentication", |
| 476 | + stream->m_unconverted_url.c_str() |
| 477 | + ); |
| 478 | + return -1; |
| 479 | + } |
476 | 480 | } |
477 | 481 |
|
478 | 482 | // Get credentials from user via libgit2 registered callback. |
479 | | - if (git_transport_smart_credentials( |
480 | | - &subtransport->m_credential, |
481 | | - subtransport->m_owner, |
482 | | - nullptr, |
483 | | - GIT_CREDENTIAL_USERPASS_PLAINTEXT |
484 | | - ) |
| 483 | + int err; |
| 484 | + if ((err = git_transport_smart_credentials( |
| 485 | + &subtransport->m_credential, |
| 486 | + subtransport->m_owner, |
| 487 | + nullptr, |
| 488 | + GIT_CREDENTIAL_USERPASS_PLAINTEXT |
| 489 | + )) |
485 | 490 | < 0) |
486 | 491 | { |
| 492 | + if (err == GIT_PASSTHROUGH) |
| 493 | + { |
| 494 | + // Use same error message as libgit2 |
| 495 | + git_error_set(GIT_ERROR_HTTP, "remote authentication required but no callback set"); |
| 496 | + } |
| 497 | + |
487 | 498 | // credentials_callback will have set git error. |
488 | | - return -1; |
| 499 | + return err; |
489 | 500 | } |
490 | 501 |
|
491 | 502 | if (subtransport->m_credential->credtype != GIT_CREDENTIAL_USERPASS_PLAINTEXT) |
|
0 commit comments