diff --git a/sdk/identity/azure-identity/src/client_secret_credential.cpp b/sdk/identity/azure-identity/src/client_secret_credential.cpp index d54bd2fee..e8b2cdc6e 100644 --- a/sdk/identity/azure-identity/src/client_secret_credential.cpp +++ b/sdk/identity/azure-identity/src/client_secret_credential.cpp @@ -3,39 +3,14 @@ #include "azure/identity/client_secret_credential.hpp" +#include #include #include -#include #include 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)