Virtru SDK for C++  2.8.0
Virtru C++ SDK library - Create, Read, and Manage TDF3 Files
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
virtru_credentials_oidc.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2020 Virtru Corporation
3  *
4  * SPDX - License - Identifier: MIT
5  *
6  */
7 //
8 // Virtru TDF3 SDK
9 //
10 // Created by Pat Mancuso on 2020/10/12
11 //
12 
13 #ifndef VIRTRU_CREDENTIALS_OIDC_H_
14 #define VIRTRU_CREDENTIALS_OIDC_H_
15 
16 #include "network_interface.h"
17 #include "virtru_credentials.h"
18 
19 namespace virtru {
20 
21  typedef std::map<std::string, std::string> OIDCHeaders;
22 
23  //Clients authenticate with Virtru services via OIDC bearer tokens
24  //Clients may authenticate with a supported OIDC IdP (identity provider)
25  //using whatever authentication methods that IdP supports in order
26  //to obtain an OIDC bearer token.
27  //Currently, this SDK supports exchanging pregenerated client credentials for an access token.
28  //Other forms of credential exchange will be added later, but for the most part the SDK shouldn't care
29  //as long as the end result is a valid OIDC bearer token it can pass along.
30 
31  class CredentialsOidc : public Credentials {
32  public:
40  CredentialsOidc(const std::string &owner,
41  const std::string &clientId,
42  const std::string &clientSecret,
43  const std::string &clientPubkey,
44  const std::string &organizationName,
45  const std::string &oidcEndpoint);
46 
55  CredentialsOidc(const std::string &owner,
56  const std::string &refreshToken,
57  const std::string &clientPubkey,
58  const std::string &organizationName,
59  const std::string &oidcEndpoint);
60 
64  CredentialsOidc(const std::string &userId,
65  const OIDCHeaders& headers);
66 
71  CredentialsOidc(const std::string &userId,
72  const std::string &authorizationString,
73  const std::string &clientToken);
74 
75 #ifndef SWIG
76  virtual std::unique_ptr<Credentials> clone() const;
79 #endif
80 
82  virtual ~CredentialsOidc();
83 
92  virtual OIDCHeaders generateAuthHeaders(const std::string &url, const std::string &method,
93  const std::string &body,
94  const std::map<std::string, std::string> &headers,
95  const std::string &date);
96 
98  virtual std::string getUserId() const;
99 
102  virtual std::string str() const;
103 
104 #ifndef SWIG
105  // This credential provider makes network calls to exchange credentials
106  // and so for testing it is extremely useful to be able to override the HTTP provider.
107  // This is obviously optional - if no provider is set, one will be created.
108  void setHTTPServiceProvider(std::weak_ptr<INetwork> httpServiceProvider);
109 #endif
110 
113  std::string getAccessToken();
114 
115  private:
116  std::tuple<std::string, std::string> exchangeCredentials(const std::string &clientId,
117  const std::string &clientSecret) const;
118 
119  std::tuple<std::string, std::string> exchangeRefresh(const std::string &refreshToken) const;
120 
121  std::tuple<std::string, std::string> userInfo(const std::string &accessToken) const;
122 
123  std::shared_ptr<INetwork> getHTTPServiceProvider() const;
124 
125  private:
126  std::weak_ptr<INetwork> m_networkServiceProvider;
127  std::string m_clientId;
128  std::string m_clientSecret;
129  std::string m_clientPubkey;
130  std::string m_orgName;
131  std::string m_oidcEndpoint;
132  std::string m_owner;
134  std::tuple<std::string, std::string> m_tokens;
135  };
136 
137 } // namespace virtru
138 #endif // VIRTRU_CREDENTIALS_OIDC_H_
std::shared_ptr< INetwork > getHTTPServiceProvider() const
std::tuple< std::string, std::string > m_tokens
Definition: virtru_credentials_oidc.h:134
std::string m_oidcEndpoint
Definition: virtru_credentials_oidc.h:131
Definition: virtru_credentials_oidc.h:31
virtual OIDCHeaders generateAuthHeaders(const std::string &url, const std::string &method, const std::string &body, const std::map< std::string, std::string > &headers, const std::string &date)
OIDCHeaders m_headers
Definition: virtru_credentials_oidc.h:133
void setHTTPServiceProvider(std::weak_ptr< INetwork > httpServiceProvider)
virtual ~CredentialsOidc()
Destructor.
std::string m_clientId
Definition: virtru_credentials_oidc.h:127
CredentialsOidc(const std::string &owner, const std::string &clientId, const std::string &clientSecret, const std::string &clientPubkey, const std::string &organizationName, const std::string &oidcEndpoint)
std::tuple< std::string, std::string > exchangeCredentials(const std::string &clientId, const std::string &clientSecret) const
Definition: virtru_credentials.h:31
std::string m_orgName
Definition: virtru_credentials_oidc.h:130
std::string m_clientPubkey
Definition: virtru_credentials_oidc.h:129
std::map< std::string, std::string > OIDCHeaders
Definition: virtru_credentials_oidc.h:21
std::weak_ptr< INetwork > m_networkServiceProvider
Definition: virtru_credentials_oidc.h:126
virtual std::string str() const
virtual std::unique_ptr< Credentials > clone() const
std::string m_owner
Definition: virtru_credentials_oidc.h:132
std::tuple< std::string, std::string > userInfo(const std::string &accessToken) const
std::string getAccessToken()
std::string m_clientSecret
Definition: virtru_credentials_oidc.h:128
virtual std::string getUserId() const
Get the userId associated with these credentials.
std::tuple< std::string, std::string > exchangeRefresh(const std::string &refreshToken) const