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  };
52 
57  public:
67  TokenRequestContext const& tokenRequestContext,
68  Context const& context) const = 0;
69 
74  virtual ~TokenCredential() = default;
75 
76  protected:
82 
83  private:
88  TokenCredential(TokenCredential const&) = delete;
89 
94  void operator=(TokenCredential const&) = delete;
95  };
96 
100  class AuthenticationException final : public std::exception {
101  std::string m_what;
102 
103  public:
109  explicit AuthenticationException(std::string what) : m_what(std::move(what)) {}
110 
118  char const* what() const noexcept override { return m_what.c_str(); }
119  };
120 }}} // namespace Azure::Core::Credentials
Azure::Core::Credentials::TokenRequestContext::Scopes
std::vector< std::string > Scopes
Authentication scopes.
Definition: credentials.hpp:50
Azure::Core::Credentials::AuthenticationException
An exception that gets thrown when an authentication error occurs.
Definition: credentials.hpp:100
Azure::Core::Credentials::AccessToken::Token
std::string Token
Token string.
Definition: credentials.hpp:32
Azure::Core::Credentials::AuthenticationException::what
char const * what() const noexcept override
Definition: credentials.hpp:118
context.hpp
Context for canceling long running operations.
Azure::Core::Credentials::AuthenticationException::AuthenticationException
AuthenticationException(std::string what)
Constructs AuthenticationException with a message string.
Definition: credentials.hpp:109
datetime.hpp
Support for date and time standardized string formats.
Azure::Core::Credentials::TokenRequestContext
Context for getting token.
Definition: credentials.hpp:45
Azure::Core::Credentials::TokenCredential
A base type of credential that uses Azure::Core::AccessToken to authenticate requests.
Definition: credentials.hpp:56
Azure::Core::Credentials::TokenCredential::TokenCredential
TokenCredential()
Constructs a default instance of TokenCredential.
Definition: credentials.hpp:81
Azure
Azure SDK abstractions.
Definition: azure_assert.hpp:55
Azure::Core::Credentials::TokenCredential::GetToken
virtual AccessToken GetToken(TokenRequestContext const &tokenRequestContext, Context const &context) const =0
Gets an authentication token.
Azure::DateTime
Manages date and time in standardized string formats.
Definition: datetime.hpp:54
Azure::Core::Credentials::AccessToken::ExpiresOn
DateTime ExpiresOn
A point in time after which the token expires.
Definition: credentials.hpp:38
Azure::Core::Credentials::AccessToken
An access token is used to authenticate requests.
Definition: credentials.hpp:27
Azure::Core::Context
A context is a node within a tree that represents deadlines and key/value pairs.
Definition: context.hpp:45
Azure::Core::Credentials::TokenCredential::~TokenCredential
virtual ~TokenCredential()=default
Destructs TokenCredential.