11#include <azure/core/credentials/credentials.hpp>
12#include <azure/core/credentials/token_credential_options.hpp>
13#include <azure/core/resource_identifier.hpp>
18#if defined(_azure_TESTING_BUILD)
20namespace Azure {
namespace Identity {
namespace Test {
21 class ManagedIdentityId_Basic_Test;
22 class ManagedIdentityId_Invalid_Test;
26namespace Azure {
namespace Identity {
28 class ManagedIdentitySource;
38 enum class ManagedIdentityIdKind
55#if defined(_azure_TESTING_BUILD)
57 friend class Azure::Identity::Test::ManagedIdentityId_Basic_Test;
58 friend class Azure::Identity::Test::ManagedIdentityId_Invalid_Test;
62 _detail::ManagedIdentityIdKind m_idKind;
86 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ClientId, std::move(
id));
96 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ObjectId, std::move(
id));
107 return ManagedIdentityId(_detail::ManagedIdentityIdKind::ResourceId,
id.ToString());
123 explicit ManagedIdentityId(_detail::ManagedIdentityIdKind idKind, std::string
id)
124 : m_idKind(idKind), m_id(id)
126 if (idKind == _detail::ManagedIdentityIdKind::SystemAssigned && !
id.empty())
128 throw std::invalid_argument(
129 "There is no need to provide an ID (such as client, object, or resource ID) if you are "
130 "using system-assigned managed identity.");
134 && (idKind == _detail::ManagedIdentityIdKind::ClientId
135 || idKind == _detail::ManagedIdentityIdKind::ObjectId
136 || idKind == _detail::ManagedIdentityIdKind::ResourceId))
138 throw std::invalid_argument(
139 "Provide the value of the client, object, or resource ID corresponding to the "
140 "ManagedIdentityIdKind specified. The provided ID should not be empty in the case of "
141 "user-assigned managed identity.");
150 std::string
const& GetId()
const {
return m_id; }
156 _detail::ManagedIdentityIdKind GetManagedIdentityIdKind()
const {
return m_idKind; }
181 std::unique_ptr<_detail::ManagedIdentitySource> m_managedIdentitySource;
197 std::string
const& clientId = std::string(),
198 Azure::Core::Credentials::TokenCredentialOptions
const& options
199 = Azure::Core::Credentials::TokenCredentialOptions());
215 Azure::Core::Credentials::TokenCredentialOptions
const& options);
227 Core::Credentials::AccessToken
GetToken(
228 Core::Credentials::TokenRequestContext
const& tokenRequestContext,
229 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:179
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:53
ManagedIdentityId()
Constructs the type of managed identity.
Definition managed_identity_credential.hpp:71
static ManagedIdentityId SystemAssigned()
Create an instance of ManagedIdentityId for a system-assigned managed identity.
Definition managed_identity_credential.hpp:77
static ManagedIdentityId FromUserAssignedResourceId(Azure::Core::ResourceIdentifier id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:105
static ManagedIdentityId FromUserAssignedClientId(std::string id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:84
static ManagedIdentityId FromUserAssignedObjectId(std::string id)
Create an instance of ManagedIdentityId for a user-assigned managed identity.
Definition managed_identity_credential.hpp:94
Options for managed identity credential.
Definition managed_identity_credential.hpp:164
ManagedIdentityId IdentityId
Specifies the type of managed identity and its corresponding identifier, based on how it was configur...
Definition managed_identity_credential.hpp:169