Official C++ SDK for Authdog authentication and user management platform.
- C++17 or higher
- CMake 3.16 or higher
- nlohmann/json - JSON library
- cpr - HTTP client library
# Install dependencies
conan install . --build=missing
# Build the project
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .# Install dependencies
vcpkg install nlohmann-json cpr
# Build the project
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
cmake --build .# Install nlohmann/json
git clone https://github.com/nlohmann/json.git
cd json
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make install
# Install cpr
git clone https://github.com/libcpr/cpr.git
cd cpr
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make install
# Build Authdog SDK
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .#include <iostream>
#include "authdog/authdog_client.h"
#include "authdog/exceptions.h"
int main() {
try {
// Initialize the client
authdog::AuthdogClient client("https://api.authdog.com");
// Get user information
auto userInfo = client.getUserInfo("your-access-token");
std::cout << "User: " << userInfo.user.displayName << std::endl;
// Close the client
client.close();
} catch (const authdog::AuthenticationException& e) {
std::cerr << "Authentication failed: " << e.what() << std::endl;
} catch (const authdog::ApiException& e) {
std::cerr << "API error: " << e.what() << std::endl;
}
return 0;
}authdog::AuthdogClient client("https://api.authdog.com");authdog::ClientConfig config;
config.baseUrl = "https://api.authdog.com";
config.apiKey = "your-api-key"; // Optional
config.timeoutSeconds = 30;
authdog::AuthdogClient client(config);// Simple constructor
AuthdogClient(const std::string& baseUrl);
// Advanced constructor
AuthdogClient(const ClientConfig& config);UserInfoResponse getUserInfo(const std::string& accessToken);Get user information using an access token.
Parameters:
accessToken: The access token for authentication
Returns: UserInfoResponse containing user information
Throws:
AuthenticationException: When authentication fails (401 responses)ApiException: When API request fails
void close();Close the HTTP client (for cleanup).
struct UserInfoResponse {
Meta meta;
Session session;
User user;
};struct User {
std::string id;
std::string externalId;
std::string userName;
std::string displayName;
std::optional<std::string> nickName;
std::optional<std::string> profileUrl;
std::optional<std::string> title;
std::optional<std::string> userType;
std::optional<std::string> preferredLanguage;
std::string locale;
std::optional<std::string> timezone;
bool active;
Names names;
std::vector<Photo> photos;
std::vector<nlohmann::json> phoneNumbers;
std::vector<nlohmann::json> addresses;
std::vector<Email> emails;
std::vector<Verification> verifications;
std::string provider;
std::string createdAt;
std::string updatedAt;
std::string environmentId;
};struct Names {
std::string id;
std::optional<std::string> formatted;
std::string familyName;
std::string givenName;
std::optional<std::string> middleName;
std::optional<std::string> honorificPrefix;
std::optional<std::string> honorificSuffix;
};struct Email {
std::string id;
std::string value;
std::optional<std::string> type;
};struct Photo {
std::string id;
std::string value;
std::string type;
};struct Verification {
std::string id;
std::string email;
bool verified;
std::string createdAt;
std::string updatedAt;
};The SDK provides structured error handling with specific exception types:
Thrown when authentication fails (401 responses).
try {
auto userInfo = client.getUserInfo("invalid-token");
} catch (const authdog::AuthenticationException& e) {
std::cerr << "Authentication failed: " << e.what() << std::endl;
}Thrown when API requests fail.
try {
auto userInfo = client.getUserInfo("valid-token");
} catch (const authdog::ApiException& e) {
std::cerr << "API error: " << e.what() << std::endl;
}Base exception class for all SDK errors.
try {
auto userInfo = client.getUserInfo("token");
} catch (const authdog::AuthdogException& e) {
std::cerr << "Authdog error: " << e.what() << std::endl;
}#include <iostream>
#include "authdog/authdog_client.h"
int main() {
authdog::AuthdogClient client("https://api.authdog.com");
auto userInfo = client.getUserInfo("your-access-token");
std::cout << "User ID: " << userInfo.user.id << std::endl;
std::cout << "Display Name: " << userInfo.user.displayName << std::endl;
std::cout << "Provider: " << userInfo.user.provider << std::endl;
if (!userInfo.user.emails.empty()) {
std::cout << "Email: " << userInfo.user.emails[0].value << std::endl;
}
client.close();
return 0;
}#include <iostream>
#include "authdog/authdog_client.h"
#include "authdog/exceptions.h"
int main() {
authdog::AuthdogClient client("https://api.authdog.com");
try {
auto userInfo = client.getUserInfo("your-access-token");
std::cout << "Success: " << userInfo.user.displayName << std::endl;
} catch (const authdog::AuthenticationException& e) {
std::cerr << "Authentication failed: " << e.what() << std::endl;
// Handle authentication error
} catch (const authdog::ApiException& e) {
std::cerr << "API error: " << e.what() << std::endl;
// Handle API error
} finally {
client.close();
}
return 0;
}#include <iostream>
#include "authdog/authdog_client.h"
void processUser() {
// Client is automatically cleaned up when it goes out of scope
authdog::AuthdogClient client("https://api.authdog.com");
try {
auto userInfo = client.getUserInfo("your-access-token");
std::cout << "=== User Information ===" << std::endl;
std::cout << "ID: " << userInfo.user.id << std::endl;
std::cout << "Display Name: " << userInfo.user.displayName << std::endl;
std::cout << "Username: " << userInfo.user.userName << std::endl;
std::cout << "Provider: " << userInfo.user.provider << std::endl;
std::cout << "Active: " << (userInfo.user.active ? "Yes" : "No") << std::endl;
if (!userInfo.user.emails.empty()) {
std::cout << "\n=== Emails ===" << std::endl;
for (const auto& email : userInfo.user.emails) {
std::cout << "- " << email.value;
if (email.type) {
std::cout << " (" << *email.type << ")";
}
std::cout << std::endl;
}
}
if (!userInfo.user.photos.empty()) {
std::cout << "\n=== Photos ===" << std::endl;
for (const auto& photo : userInfo.user.photos) {
std::cout << "- " << photo.value << " (" << photo.type << ")" << std::endl;
}
}
} catch (const authdog::AuthenticationException& e) {
std::cerr << "Authentication failed: " << e.what() << std::endl;
} catch (const authdog::ApiException& e) {
std::cerr << "API error: " << e.what() << std::endl;
}
// Client is automatically closed here
}
int main() {
processUser();
return 0;
}#include <iostream>
#include "authdog/authdog_client.h"
authdog::AuthdogClient createClient() {
return authdog::AuthdogClient("https://api.authdog.com");
}
int main() {
// Move constructor
auto client = createClient();
try {
auto userInfo = client.getUserInfo("your-access-token");
std::cout << "User: " << userInfo.user.displayName << std::endl;
} catch (const authdog::ApiException& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .# Build tests
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build .
# Run tests
ctest --output-on-failure# Build example
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --target authdog_example
# Run example
./authdog_example# Find the Authdog C++ SDK
find_package(AuthdogCppSdk REQUIRED)
# Link against the library
target_link_libraries(your_target authdog_cpp_sdk)# conanfile.txt
[requires]
authdog-cpp-sdk/0.1.0
[generators]
CMakeDeps
CMakeToolchain- C++17 compiler (GCC 7+, Clang 5+, MSVC 2017+)
- CMake 3.16+
- nlohmann/json
- cpr
- Google Test (for testing)
- Follow Google C++ Style Guide
- Use
clang-formatfor formatting - Use
clang-tidyfor static analysis - Maximum line length: 100 characters
- Use
constwherever possible - Prefer
std::string_viewfor read-only string parameters
# Install Google Test
# Ubuntu/Debian
sudo apt-get install libgtest-dev
# macOS
brew install googletest
# Build and run tests
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build .
ctest --output-on-failureMIT License - see LICENSE for details.