Add authority URL support for ClientSecretCredential (#424)
This commit is contained in:
parent
68643e3ee2
commit
302bbf251e
@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user