Add authority URL support for ClientSecretCredential (#424)

This commit is contained in:
Anton Kolesnyk 2020-08-11 11:22:09 -07:00 committed by GitHub
parent 68643e3ee2
commit 302bbf251e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -34,17 +34,21 @@ namespace Azure { namespace Core { namespace Credentials {
class ClientSecretCredential : public TokenCredential {
private:
static std::string const g_aadGlobalAuthority;
std::string const m_tenantId;
std::string const m_clientId;
std::string const m_clientSecret;
std::string const m_authority;
public:
explicit ClientSecretCredential(
std::string tenantId,
std::string clientId,
std::string clientSecret)
std::string clientSecret,
std::string authority = g_aadGlobalAuthority)
: m_tenantId(std::move(tenantId)), m_clientId(std::move(clientId)),
m_clientSecret(std::move(clientSecret))
m_clientSecret(std::move(clientSecret)), m_authority(std::move(authority))
{
}

View File

@ -37,7 +37,10 @@ std::string UrlEncode(std::string const& s)
}
} // namespace
AccessToken ClientSecretCredential::GetToken(
std::string const Azure::Core::Credentials::ClientSecretCredential::g_aadGlobalAuthority
= "https://login.microsoftonline.com/";
AccessToken Azure::Core::Credentials::ClientSecretCredential::GetToken(
Context const& context,
std::vector<std::string> const& scopes) const
{
@ -45,7 +48,7 @@ AccessToken ClientSecretCredential::GetToken(
try
{
std::ostringstream url;
url << "https://login.microsoftonline.com/" << UrlEncode(m_tenantId) << "/oauth2/v2.0/token";
url << m_authority << UrlEncode(m_tenantId) << "/oauth2/v2.0/token";
std::ostringstream body;
body << "grant_type=client_credentials&client_id=" << UrlEncode(m_clientId)