11#include <azure/core/credentials/credentials.hpp>
12#include <azure/core/credentials/token_credential_options.hpp>
13#include <azure/core/resource_identifier.hpp>
19#if defined(_azure_TESTING_BUILD)
21namespace Azure {
namespace Identity {
namespace Test {
22 class ManagedIdentityId_Basic_Test;
23 class ManagedIdentityId_Invalid_Test;
27namespace Azure {
namespace Identity {
29 class ManagedIdentitySource;
39 enum class ManagedIdentityIdKind
56#if defined(_azure_TESTING_BUILD)
58 friend class Azure::Identity::Test::ManagedIdentityId_Basic_Test;
59 friend class Azure::Identity::Test::ManagedIdentityId_Invalid_Test;
63 _detail::ManagedIdentityIdKind m_idKind;
87 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ClientId, std::move(
id));
97 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ObjectId, std::move(
id));
108 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ResourceId,
id.ToString());
124 explicit ManagedIdentityId(_detail::ManagedIdentityIdKind idKind, std::string
id)
125 : m_idKind(idKind), m_id(std::move(id))
127 if (idKind == _detail::ManagedIdentityIdKind::SystemAssigned && !m_id.empty())
129 throw std::invalid_argument(
130 "There is no need to provide an ID (such as client, object, or resource ID) if you are "
131 "using system-assigned managed identity.");
135 && (idKind == _detail::ManagedIdentityIdKind::ClientId
136 || idKind == _detail::ManagedIdentityIdKind::ObjectId
137 || idKind == _detail::ManagedIdentityIdKind::ResourceId))
139 throw std::invalid_argument(
140 "Provide the value of the client, object, or resource ID corresponding to the "
141 "ManagedIdentityIdKind specified. The provided ID should not be empty in the case of "
142 "user-assigned managed identity.");
151 std::string
const& GetId()
const {
return m_id; }
157 _detail::ManagedIdentityIdKind GetManagedIdentityIdKind()
const {
return m_idKind; }
182 std::unique_ptr<_detail::ManagedIdentitySource> m_managedIdentitySource;
198 std::string
const& clientId = std::string(),
199 Azure::Core::Credentials::TokenCredentialOptions
const& options
200 = Azure::Core::Credentials::TokenCredentialOptions());
216 Azure::Core::Credentials::TokenCredentialOptions
const& options);
228 Core::Credentials::AccessToken
GetToken(
229 Core::Credentials::TokenRequestContext
const& tokenRequestContext,
230 Core::Context
const& context)
const override;
Attempts authentication using a managed identity that has been assigned to the deployment environment...
Definition managed_identity_credential.hpp:180
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition managed_identity_credential.cpp:95
~ManagedIdentityCredential() override
Destructs TokenCredential.
The type of managed identity and its corresponding identifier.
Definition managed_identity_credential.hpp:54
ManagedIdentityId()
Constructs the type of managed identity.
Definition managed_identity_credential.hpp:72
static ManagedIdentityId FromUserAssignedResourceId(Azure::Core::ResourceIdentifier const &id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:106
static ManagedIdentityId SystemAssigned()
Create an instance of ManagedIdentityId for a system-assigned managed identity.
Definition managed_identity_credential.hpp:78
static ManagedIdentityId FromUserAssignedClientId(std::string id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:85
static ManagedIdentityId FromUserAssignedObjectId(std::string id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:95
Options for managed identity credential.
Definition managed_identity_credential.hpp:165
ManagedIdentityId IdentityId
Specifies the type of managed identity and its corresponding identifier, based on how it was configur...
Definition managed_identity_credential.hpp:170