Use Url::Encode() instead of the own implementation (#1614)
Closes #738.
This commit is contained in:
parent
1c26120654
commit
b55063dfac
@ -3,39 +3,14 @@
|
||||
|
||||
#include "azure/identity/client_secret_credential.hpp"
|
||||
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/http/pipeline.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Azure::Identity;
|
||||
|
||||
namespace {
|
||||
std::string UrlEncode(std::string const& s)
|
||||
{
|
||||
std::ostringstream encoded;
|
||||
encoded << std::hex;
|
||||
|
||||
for (auto c : s)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|
||||
|| (c == '-' || c == '.' || c == '_' || c == '~'))
|
||||
{
|
||||
encoded << c;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoded << std::uppercase;
|
||||
encoded << '%' << std::setw(2) << int((unsigned char)c);
|
||||
encoded << std::nouppercase;
|
||||
}
|
||||
}
|
||||
|
||||
return encoded.str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string const Azure::Identity::Details::g_aadGlobalAuthority
|
||||
= "https://login.microsoftonline.com/";
|
||||
|
||||
@ -54,15 +29,14 @@ Azure::Core::AccessToken ClientSecretCredential::GetToken(
|
||||
url.AppendPath("oauth2/v2.0/token");
|
||||
|
||||
std::ostringstream body;
|
||||
// TODO: Use encoding from Http::Url::Encode once it becomes public
|
||||
body << "grant_type=client_credentials&client_id=" << UrlEncode(m_clientId)
|
||||
<< "&client_secret=" << UrlEncode(m_clientSecret);
|
||||
body << "grant_type=client_credentials&client_id=" << Url::Encode(m_clientId)
|
||||
<< "&client_secret=" << Url::Encode(m_clientSecret);
|
||||
|
||||
auto const& scopes = tokenRequestOptions.Scopes;
|
||||
if (!scopes.empty())
|
||||
{
|
||||
auto scopesIter = scopes.begin();
|
||||
body << "&scope=" << UrlEncode(*scopesIter);
|
||||
body << "&scope=" << Url::Encode(*scopesIter);
|
||||
|
||||
auto const scopesEnd = scopes.end();
|
||||
for (++scopesIter; scopesIter != scopesEnd; ++scopesIter)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user