-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthServer.hpp
113 lines (66 loc) · 3.73 KB
/
AuthServer.hpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*++
Program name:
Apostol CRM
Module Name:
AuthServer.hpp
Notices:
Module: OAuth 2 Authorization Server
Author:
Copyright (c) Prepodobny Alen
mailto: [email protected]
mailto: [email protected]
--*/
#ifndef APOSTOL_AUTHSERVER_HPP
#define APOSTOL_AUTHSERVER_HPP
//----------------------------------------------------------------------------------------------------------------------
extern "C++" {
namespace Apostol {
namespace Module {
//--------------------------------------------------------------------------------------------------------------
//-- CAuthServer -----------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
class CAuthServer: public CApostolModule {
private:
CDateTime m_FixedDate;
void InitMethods() override;
void FetchAccessToken(CHTTPServerConnection *AConnection, const CProvider &Provider, const CString& Code);
void FetchCerts(CProvider &Provider);
void FetchProviders();
void CheckProviders();
static void AfterQuery(CHTTPServerConnection *AConnection, const CString &Path, const CJSON &Payload);
void QueryException(CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E);
CString CreateToken(const CCleanToken& CleanToken);
CString VerifyToken(const CString &Token);
static void ParseString(const CString &String, const CStringList &Strings, CStringList &Valid, CStringList &Invalid);
static bool CheckAuthorizationData(const CHTTPRequest &Request, CAuthorization &Authorization);
static int CheckOAuth2Error(const CJSON &Json, CString &Error, CString &ErrorDescription);
static int CheckError(const CJSON &Json, CString &ErrorMessage, bool RaiseIfError = false);
static CHTTPReply::CStatusType ErrorCodeToStatus(int ErrorCode);
void RedirectError(CHTTPServerConnection *AConnection, const CString &Location, int ErrorCode, const CString &Error, const CString &Message);
static void ReplyError(CHTTPServerConnection *AConnection, int ErrorCode, const CString &Error, const CString &Message);
static void SetAuthorizationData(CHTTPServerConnection *AConnection, const CJSON &Payload);
static void SetSecure(CHTTPReply &Reply, const CString &AccessToken, const CString &RefreshToken, const CString &Session, const CString &Domain);
void Login(CHTTPServerConnection *AConnection, const CJSON &Token);
protected:
void DoGet(CHTTPServerConnection *AConnection) override;
void DoPost(CHTTPServerConnection *AConnection);
void DoToken(CHTTPServerConnection *AConnection);
void DoIdentifier(CHTTPServerConnection *AConnection);
void DoPostgresQueryExecuted(CPQPollQuery *APollQuery) override;
void DoPostgresQueryException(CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E) override;
public:
explicit CAuthServer(CModuleProcess *AProcess);
~CAuthServer() override = default;
static class CAuthServer *CreateModule(CModuleProcess *AProcess) {
return new CAuthServer(AProcess);
}
bool CheckAuthorization(CHTTPServerConnection *AConnection, CAuthorization &Authorization);
void Heartbeat(CDateTime DateTime) override;
bool Enabled() override;
bool CheckLocation(const CLocation &Location) override;
};
}
}
using namespace Apostol::Module;
}
#endif //APOSTOL_AUTHSERVER_HPP