Add libhv and test http client

This commit is contained in:
Guilherme Werner
2023-12-03 16:38:19 -03:00
parent 7297e2e383
commit 4fb0abd834
102 changed files with 60661 additions and 26 deletions

View File

@ -3,5 +3,5 @@
#pragma once
#include <tribufu/defines.h>
#include <tribufu/platform.h>
#include <tribufu/platform/platform.h>
#include <tribufu/std.h>

View File

@ -3,6 +3,8 @@
#pragma once
#include <tribufu/base.h>
#include <tribufu/json.h>
#include <tribufu/http.h>
const char *VERSION = "0.0.4";
@ -13,6 +15,7 @@ namespace tribufu
private:
uint64_t id;
std::string secret;
hv::HttpClient http;
public:
TribufuClient(uint64_t id, const std::string &secret);
@ -22,5 +25,7 @@ namespace tribufu
{
return this->id;
}
void get_token();
};
}

5
include/tribufu/http.h Normal file
View File

@ -0,0 +1,5 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <hv/requests.h>

7
include/tribufu/json.h Normal file
View File

@ -0,0 +1,7 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <nlohmann/json.hpp>
using json = nlohmann::json;

127
include/tribufu/oauth2.h Normal file
View File

@ -0,0 +1,127 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <tribufu/base.h>
namespace tribufu
{
enum class TRIBUFU_API OAuth2ResponseType
{
Code,
Token,
};
enum class TRIBUFU_API OAuth2ClientType
{
Confidential,
Public,
};
enum class TRIBUFU_API OAuth2TokenHintType
{
AccessToken,
RefreshToken,
};
enum class TRIBUFU_API OAuth2GrantType
{
AuthorizationCode,
ClientCredentials,
DeviceCode,
Password,
RefreshToken,
};
enum class TRIBUFU_API OAuth2AuthorizeError
{
AccessDenied,
InvalidRequest,
InvalidScope,
ServerError,
TemporarilyUnavailable,
UnauthorizedClient,
UnsupportedResponseType,
};
enum class TRIBUFU_API OAuth2TokenType
{
Bearer,
};
class TRIBUFU_API OAuth2AuthorizeRequest
{
private:
OAuth2ResponseType response_type;
uint64_t client_id;
std::string client_secret;
std::string redirect_uri;
std::string scope;
std::string state;
public:
OAuth2AuthorizeRequest();
OAuth2AuthorizeRequest(OAuth2ResponseType response_type, uint64_t client_id, const std::string &client_secret, const std::string &redirect_uri, const std::string &scope, const std::string &state);
~OAuth2AuthorizeRequest();
};
class TRIBUFU_API OAuth2CodeResponse
{
private:
std::string code;
std::string state;
public:
OAuth2CodeResponse();
OAuth2CodeResponse(const std::string &code, const std::string &state);
~OAuth2CodeResponse();
};
class TRIBUFU_API OAuth2ErrorResponse
{
private:
OAuth2AuthorizeError error;
std::string error_description;
std::string error_uri;
std::string state;
public:
OAuth2ErrorResponse();
OAuth2ErrorResponse(OAuth2AuthorizeError error, const std::string &error_description, const std::string &error_uri, const std::string &state);
~OAuth2ErrorResponse();
};
class TRIBUFU_API OAuth2TokenRequest
{
private:
OAuth2GrantType grant_type;
uint64_t client_id;
std::string client_secret;
std::string redirect_uri;
std::string code;
std::string refresh_token;
std::string username;
std::string password;
public:
OAuth2TokenRequest();
OAuth2TokenRequest(OAuth2GrantType grant_type, uint64_t client_id, const std::string &client_secret, const std::string &redirect_uri, const std::string &code, const std::string &refresh_token, const std::string &username, const std::string &password);
~OAuth2TokenRequest();
};
class TRIBUFU_API OAuth2TokenResponse
{
private:
OAuth2TokenType token_type;
std::string access_token;
std::string refresh_token;
std::string scope;
std::string state;
uint64_t expires_in;
public:
OAuth2TokenResponse();
OAuth2TokenResponse(OAuth2TokenType token_type, const std::string &access_token, const std::string &refresh_token, const std::string &scope, const std::string &state, uint64_t expires_in);
~OAuth2TokenResponse();
};
}

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/unix/unix_platform.h>
#include <tribufu/platform/unix.h>
#ifndef TRIBUFU_ANDROID
#define TRIBUFU_ANDROID

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/unix/unix_platform.h>
#include <tribufu/platform/unix.h>
#ifndef TRIBUFU_FREEBSD
#define TRIBUFU_FREEBSD

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/apple/apple_platform.h>
#include <tribufu/platform/apple.h>
#ifndef TRIBUFU_IOS
#define TRIBUFU_IOS

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/unix/unix_platform.h>
#include <tribufu/platform/unix.h>
#ifndef TRIBUFU_LINUX
#define TRIBUFU_LINUX

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/apple/apple_platform.h>
#include <tribufu/platform/apple.h>
#ifndef TRIBUFU_MAC
#define TRIBUFU_MAC

View File

@ -3,28 +3,28 @@
#pragma once
#ifdef _WIN32
#include <tribufu/windows/windows_platform.h>
#include <tribufu/platform/windows.h>
#endif
#ifdef __MACH__
#include <tribufu/mac/mac_platform.h>
#include <tribufu/platform/mac.h>
#endif
#ifdef __linux__
#include <tribufu/linux/linux_platform.h>
#include <tribufu/platform/linux.h>
#endif
#ifdef __FreeBSD__
#include <tribufu/freebsd/freebsd_platform.h>
#include <tribufu/platform/freebsd.h>
#endif
#ifdef __ANDROID__
#include <tribufu/android/android_platform.h>
#include <tribufu/platform/android.h>
#endif
#ifdef __APPLE__
// #include <TargetConditionals.h>
#ifdef TARGET_OS_IPHONE
#include <tribufu/ios/ios_platform.h>
#include <tribufu/platform/ios.h>
#endif
#endif

View File

@ -2,7 +2,7 @@
#pragma once
#include <tribufu/msvc/msvc_platform.h>
#include <tribufu/platform/msvc.h>
#ifndef TRIBUFU_WINDOWS
#define TRIBUFU_WINDOWS

View File

@ -1,9 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <tribufu/msvc/msvc_platform.h>
#ifndef TRIBUFU_UWP
#define TRIBUFU_UWP
#endif