azure-core
credentials.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
9 #pragma once
10 
11 #include "azure/core/context.hpp"
12 #include "azure/core/datetime.hpp"
13 
14 #include <exception>
15 #include <memory>
16 #include <mutex>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace Azure { namespace Core { namespace Credentials {
22 
26  struct AccessToken final
27  {
32  std::string Token;
33 
39  };
40 
44  struct TokenRequestContext final
45  {
50  std::vector<std::string> Scopes;
51 
56  DateTime::duration MinimumExpiration = std::chrono::minutes(2);
57  };
58 
63  public:
75  TokenRequestContext const& tokenRequestContext,
76  Context const& context) const = 0;
77 
82  virtual ~TokenCredential() = default;
83 
84  protected:
90 
91  private:
96  TokenCredential(TokenCredential const&) = delete;
97 
102  void operator=(TokenCredential const&) = delete;
103  };
104 
108  class AuthenticationException final : public std::exception {
109  std::string m_what;
110 
111  public:
117  explicit AuthenticationException(std::string what) : m_what(std::move(what)) {}
118 
126  char const* what() const noexcept override { return m_what.c_str(); }
127  };
128 }}} // namespace Azure::Core::Credentials
A context is a node within a tree that represents deadlines and key/value pairs.
Definition: context.hpp:45
An exception that gets thrown when an authentication error occurs.
Definition: credentials.hpp:108
char const * what() const noexcept override
Definition: credentials.hpp:126
AuthenticationException(std::string what)
Constructs AuthenticationException with a message string.
Definition: credentials.hpp:117
A base type of credential that uses Azure::Core::AccessToken to authenticate requests.
Definition: credentials.hpp:62
virtual AccessToken GetToken(TokenRequestContext const &tokenRequestContext, Context const &context) const =0
Gets an authentication token.
TokenCredential()
Constructs a default instance of TokenCredential.
Definition: credentials.hpp:89
virtual ~TokenCredential()=default
Destructs TokenCredential.
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.
Azure SDK abstractions.
Definition: azure_assert.hpp:55
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