-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
77 lines (64 loc) · 2.16 KB
/
Copy pathexample.cpp
File metadata and controls
77 lines (64 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Authon C++ SDK - Full Usage Example
* Compile: g++ -O2 -o example.exe example.cpp -lwinhttp
* or: cl example.cpp winhttp.lib
*/
#include <iostream>
#include <string>
#include <conio.h>
#include "authon.h"
int main() {
// ============ SETUP ============
authon::Authon auth("your-app-id", "your-api-key");
// ============ CONNECT ============
std::cout << "[*] Connecting...\n";
if (!auth.init()) {
std::cout << "[-] Failed to connect to Authon API\n";
return 1;
}
std::cout << "[+] Connected: " << auth.appName << " v" << auth.appVersion << "\n";
// ============ AUTHENTICATE ============
std::cout << "\n[1] Login (Username + Password)\n";
std::cout << "[2] License Key\n";
std::cout << "\n> ";
int choice = _getch() - '0';
std::cout << choice << "\n\n";
bool success = false;
if (choice == 1) {
std::string username, password;
std::cout << "Username: ";
std::getline(std::cin, username);
std::cout << "Password: ";
std::getline(std::cin, password);
success = auth.login(username, password);
} else {
std::string key;
std::cout << "License Key: ";
std::getline(std::cin, key);
success = auth.license(key);
}
if (!success) {
std::cout << "\n[-] " << auth.lastError << "\n";
system("pause");
return 1;
}
std::cout << "\n[+] Authenticated!\n";
std::cout << " Level: " << auth.level << "\n";
std::cout << " Subscription: " << (auth.subscription.empty() ? "None" : auth.subscription) << "\n";
std::cout << " Expires: " << (auth.expiresAt.empty() ? "Lifetime" : auth.expiresAt) << "\n";
// ============ USE FEATURES ============
// Get variable
std::string msg = auth.getVar("welcome_message");
if (!msg.empty())
std::cout << "\n[*] " << msg << "\n";
// Log activity
auth.log("C++ SDK example executed");
// Session check
if (auth.check())
std::cout << "\n[+] Session is valid\n";
// ============ CLEANUP ============
std::cout << "\n[+] Done. Logging out...\n";
auth.logout();
system("pause");
return 0;
}