Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5662: Derive the resource/account identifier used to access the Wind…
…ows CredentialManager.
  • Loading branch information
codereader committed Jul 6, 2021
1 parent d28f089 commit 92bc964
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugins/vcs/CredentialManager.h
Expand Up @@ -16,6 +16,11 @@ namespace vcs
class CredentialManager
{
public:
static std::pair<std::string, std::string> RetrievePassword(const std::string& accountName)
{
return RetrievePassword(string::utf8_to_unicode(accountName));
}

static std::pair<std::string, std::string> RetrievePassword(const std::wstring& accountName)
{
#ifdef _MSC_VER
Expand Down
14 changes: 12 additions & 2 deletions plugins/vcs/Remote.h
Expand Up @@ -3,6 +3,8 @@
#include <git2.h>
#include "Repository.h"
#include "CredentialManager.h"
#include <wx/uri.h>
#include <fmt/format.h>

namespace vcs
{
Expand Down Expand Up @@ -35,14 +37,22 @@ class Remote final
return;
}

auto url = wxURI(git_remote_url(_remote));

git_fetch_options options;
git_fetch_options_init(&options, GIT_FETCH_OPTIONS_VERSION);

git_credential* credentials = nullptr;
auto userAndPass = CredentialManager::RetrievePassword(L"git:https://gitlab.com");
// Create the git:scheme://server string to query the credential manager
auto credentialResource = fmt::format("git:{0}://{1}", url.GetScheme().ToStdString(), url.GetServer().ToStdString());

auto userAndPass = CredentialManager::RetrievePassword(credentialResource);

if (!userAndPass.first.empty() && !userAndPass.second.empty())
{
rMessage() << "Found credentials for resource " << credentialResource << " in the credential store" << std::endl;

git_credential* credentials = nullptr;

if (git_credential_userpass_plaintext_new(&credentials, userAndPass.first.c_str(), userAndPass.second.c_str()) < 0)
{
rError() << "Unable to create credentials" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions plugins/vcs/ui/VcsStatus.h
Expand Up @@ -2,6 +2,7 @@

#include "i18n.h"
#include "iuserinterface.h"
#include "imainframe.h"
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/sizer.h>
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/post_build_event.cmd
Expand Up @@ -24,6 +24,7 @@ copy ..\..\w32deps\wxWidgets\bin\wxbase313%WXLIB_SUFFIX%_xml_vc*.dll ..\..\inst
copy ..\..\w32deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_adv_vc*.dll ..\..\install /Y
copy ..\..\w32deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_core_vc*.dll ..\..\install /Y
copy ..\..\w32deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_aui_vc*.dll ..\..\install /Y
copy ..\..\w32deps\wxWidgets\bin\wxbase313%WXLIB_SUFFIX%_net_vc*.dll ..\..\install /Y

IF "%1" == "Debug" (SET DEBUG_SUFFIX=-d) ELSE (SET DEBUG_SUFFIX=)

Expand Down
1 change: 1 addition & 0 deletions tools/msvc/post_build_event_x64.cmd
Expand Up @@ -24,6 +24,7 @@ copy ..\..\w64deps\wxWidgets\bin\wxbase313%WXLIB_SUFFIX%_xml_vc*_x64.dll ..\..\
copy ..\..\w64deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_adv_vc*_x64.dll ..\..\install /Y
copy ..\..\w64deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_core_vc*_x64.dll ..\..\install /Y
copy ..\..\w64deps\wxWidgets\bin\wxmsw313%WXLIB_SUFFIX%_aui_vc*_x64.dll ..\..\install /Y
copy ..\..\w64deps\wxWidgets\bin\wxbase313%WXLIB_SUFFIX%_net_vc*_x64.dll ..\..\install /Y

IF "%1" == "Debug" (SET DEBUG_SUFFIX=-d) ELSE (SET DEBUG_SUFFIX=)

Expand Down

0 comments on commit 92bc964

Please sign in to comment.