[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/QuantStack/git2cpp/0.0.12/src/utils/credentials.cpp [Back]  [Original]

#include "credentials.hpp"

#include 

#include 

#include "input_output.hpp"

// git_credential_acquire_cb
int user_credentials(
    git_credential** out,
    const char* url,
    const char* username_from_url,
    unsigned int allowed_types,
    void* payload
)
{
    // Check for cached credentials here, if desired.
    // It might be necessary to make this function stateful to avoid repeating unnecessary checks.

    *out = nullptr;

    if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
    {
        std::string username = username_from_url ? username_from_url : "";
        if (username.empty())
        {
            username = trim(prompt_input("Username: "));
        }
        if (username.empty())
        {
            giterr_set_str(GIT_ERROR_HTTP, "No username specified");
            return GIT_EAUTH;
        }

        std::string password = trim(prompt_input("Password: ", false));
        if (password.empty())
        {
            giterr_set_str(GIT_ERROR_HTTP, "No password specified");
            return GIT_EAUTH;
        }

        // If successful, this will create and return a git_credential* in the out argument.
        return git_credential_userpass_plaintext_new(out, username.c_str(), password.c_str());
    }

    giterr_set_str(GIT_ERROR_HTTP, "Unexpected credentials request");
    return GIT_ERROR;
}

bool want_user_credentials()
{
    const char* env_var = std::getenv("GIT_CREDENTIAL_CALLBACK");
    return env_var == nullptr || std::string_view(env_var) != "0";
}

Web Proxy Viewer  |  New URL  |  Original Page