azure-core
Loading...
Searching...
No Matches
credentials.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
9#pragma once
10
13
14#include <exception>
15#include <memory>
16#include <mutex>
17#include <string>
18#include <utility>
19#include <vector>
20
21namespace Azure { namespace Core { namespace Credentials {
22
26 struct AccessToken final
27 {
32 std::string Token;
33
39 };
40
45 {
50 std::vector<std::string> Scopes;
51
56 DateTime::duration MinimumExpiration = std::chrono::minutes(2);
57
62 std::string TenantId;
63 };
64
69 private:
70 std::string m_credentialName;
71
72 public:
84 AZ_CORE_DLLEXPORT virtual AccessToken GetToken(
85 TokenRequestContext const& tokenRequestContext,
86 Context const& context) const = 0;
87
92 std::string const& GetCredentialName() const { return m_credentialName; }
93
99 AZ_CORE_DLLEXPORT virtual ~TokenCredential() = default;
100
101 protected:
107 TokenCredential(std::string const& credentialName)
108 : m_credentialName(credentialName.empty() ? "Custom Credential" : credentialName)
109 {
110 }
111
117 [[deprecated("Use the constructor with parameter.")]] TokenCredential()
118 : TokenCredential(std::string{})
119 {
120 }
121
122 private:
127 TokenCredential(TokenCredential const&) = delete;
128
133 void operator=(TokenCredential const&) = delete;
134 };
135
139 class AuthenticationException final : public std::exception {
140 std::string m_what;
141
142 public:
148 explicit AuthenticationException(std::string what) : m_what(std::move(what)) {}
149
157 char const* what() const noexcept override { return m_what.c_str(); }
158 };
159}}} // namespace Azure::Core::Credentials
A context is a node within a unidirectional tree that represents deadlines and key/value pairs.
Definition context.hpp:72
An exception that gets thrown when an authentication error occurs.
Definition credentials.hpp:139
AuthenticationException(std::string what)
Constructs AuthenticationException with a message string.
Definition credentials.hpp:148
char const * what() const noexcept override
Definition credentials.hpp:157
A base type of credential that uses Azure::Core::AccessToken to authenticate requests.
Definition credentials.hpp:68
virtual AZ_CORE_DLLEXPORT ~TokenCredential()=default
Destructs TokenCredential.
virtual AZ_CORE_DLLEXPORT AccessToken GetToken(TokenRequestContext const &tokenRequestContext, Context const &context) const =0
Gets an authentication token.
std::string const & GetCredentialName() const
Gets the name of the credential.
Definition credentials.hpp:92
TokenCredential()
Constructs a default instance of TokenCredential.
Definition credentials.hpp:117
TokenCredential(std::string const &credentialName)
Constructs an instance of TokenCredential.
Definition credentials.hpp:107
Manages date and time in standardized string formats.
Definition datetime.hpp:54
Context for canceling long running operations.
Support for date and time standardized string formats.
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
An access token is used to authenticate requests.
Definition credentials.hpp:27
std::string Token
Token string.
Definition credentials.hpp:32
DateTime ExpiresOn
A point in time after which the token expires.
Definition credentials.hpp:38
Context for getting token.
Definition credentials.hpp:45
std::vector< std::string > Scopes
Authentication scopes.
Definition credentials.hpp:50
DateTime::duration MinimumExpiration
Minimum token expiration suggestion.
Definition credentials.hpp:56
std::string TenantId
Tenant ID.
Definition credentials.hpp:62