Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"label": "Run Server Debug (Static)",
"type": "shell",
"command": "./bankid_server.exe",
"args": ["8080"],
"options": {
"cwd": "${workspaceFolder}/build/vs2022-deb/server/Debug"
},
Expand All @@ -15,6 +16,7 @@
"label": "Run Server Debug (Shared)",
"type": "shell",
"command": "./bankid_server.exe",
"args": ["8080"],
"group": "test",
"options": {
"cwd": "${workspaceFolder}/build/vs2022-deb-shared/server/Debug"
Expand All @@ -25,6 +27,7 @@
"label": "Run Server Release (Static)",
"type": "shell",
"command": "./bankid_server.exe",
"args": ["8080"],
"options": {
"cwd": "${workspaceFolder}/build/vs2022-rel/server/Release"
},
Expand All @@ -35,6 +38,7 @@
"label": "Run Server Release (Shared)",
"type": "shell",
"command": "./bankid_server.exe",
"args": ["8080"],
"group": "test",
"options": {
"cwd": "${workspaceFolder}/build/vs2022-rel-shared/server/Release"
Expand Down Expand Up @@ -62,6 +66,6 @@
"group": "test",
"dependsOn": "Build Tests (Shared)",
"problemMatcher": []
},
}
]
}
5 changes: 5 additions & 0 deletions bankid/includes/api/auth.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_AUTH_H
#define BANKID_API_AUTH_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -218,3 +221,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_AUTH_H
5 changes: 5 additions & 0 deletions bankid/includes/api/cancel.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_CANCEL_H
#define BANKID_API_CANCEL_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -47,3 +50,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_CANCEL_H
5 changes: 5 additions & 0 deletions bankid/includes/api/collect.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_COLLECT_H
#define BANKID_API_COLLECT_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -47,3 +50,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_COLLECT_H
5 changes: 5 additions & 0 deletions bankid/includes/api/other.payment.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_OTHER_PAYMENT_H
#define BANKID_API_OTHER_PAYMENT_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -280,3 +283,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_OTHER_PAYMENT_H
5 changes: 5 additions & 0 deletions bankid/includes/api/payment.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_PAYMENT_H
#define BANKID_API_PAYMENT_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -328,3 +331,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_PAYMENT_H
5 changes: 5 additions & 0 deletions bankid/includes/api/phone.auth.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_PHONE_AUTH_H
#define BANKID_API_PHONE_AUTH_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -155,3 +158,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_PHONE_AUTH_H
5 changes: 5 additions & 0 deletions bankid/includes/api/phone.sign.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_PHONE_SIGN_H
#define BANKID_API_PHONE_SIGN_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -148,3 +151,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_PHONE_SIGN_H
7 changes: 6 additions & 1 deletion bankid/includes/api/responses.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_RESPONSES_H
#define BANKID_API_RESPONSES_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -256,4 +259,6 @@ namespace BankID::API
if (j.contains("hintCode"))
r.hintCode = j.at("hintCode").get<std::string>();
}
}
} // namespace BankID::API

#endif // BANKID_API_RESPONSES_H
5 changes: 5 additions & 0 deletions bankid/includes/api/sign.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef BANKID_API_SIGN_H
#define BANKID_API_SIGN_H

#pragma once

#include "../bankid.h"
Expand Down Expand Up @@ -210,3 +213,5 @@ namespace BankID::API
};

} // namespace BankID::API

#endif // BANKID_API_SIGN_H
17 changes: 16 additions & 1 deletion bankid/includes/bankid.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
//
// bankid.h
//
// Copyright (c) 2025 Forsrobin. All rights reserved.
// MIT License
//
// This file is part of the BankID C++ library, providing a client for the BankID API.
//


#ifndef BANKID_H
#define BANKID_H

#pragma once

#define CPPHTTPLIB_OPENSSL_SUPPORT
Expand Down Expand Up @@ -99,7 +112,7 @@ namespace BankID
* For example:
* openssl pkcs12 -in bankid_cert.p12 -out bankid_key.pem -nocerts -nodes
* openssl pkcs12 -in bankid_cert.p12 -out bankid_cert.pem -clcerts -nokeys
*
*
* This structure is used to initialize the SSL client with the correct paths for the CA file, certificate, and key.
*/
struct BANKID_API SSLConfig
Expand Down Expand Up @@ -356,3 +369,5 @@ namespace BankID
#ifdef _WIN32
#pragma warning(pop)
#endif

#endif // BANKID_H
6 changes: 5 additions & 1 deletion server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ find_package(Crow REQUIRED)
find_package(nlohmann_json REQUIRED)

# Server executable
add_executable(bankid_server main.cpp)
add_executable(bankid_server
main.cpp
webserver.cpp
routes.cpp
)

# Enable SSL compilation flag
if (CROW_ENABLE_SSL)
Expand Down
9 changes: 0 additions & 9 deletions server/includes/helper.h

This file was deleted.

50 changes: 50 additions & 0 deletions server/includes/routes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef ROUTES_H
#define ROUTES_H

#pragma once

#include "bankid.h"
#include <crow.h>
#include <crow/middlewares/cors.h>
#include <nlohmann/json.hpp>
#include <vector>
#include <string>

using json = nlohmann::json;

struct EndpointInfo
{
std::string method;
std::string path;
std::string description;
};

class Routes
{
public:
static void setupRoutes(crow::App<crow::CORSHandler> &app,
BankID::Session &bankidSession,
BankID::API::AuthConfig &authConfig);

static const std::vector<EndpointInfo> &getEndpoints();

private:
// Static member definition
inline static std::vector<EndpointInfo> endpoints;

static void registerEndpoint(const std::string &method,
const std::string &path,
const std::string &description);

static crow::response handleAuthInit(BankID::Session &bankidSession,
BankID::API::AuthConfig &authConfig);

static crow::response handleAuthPoll(BankID::Session &bankidSession,
BankID::API::AuthConfig &authConfig,
const std::string &orderRef);

static crow::response handleAuthCancel(BankID::Session &bankidSession,
const std::string &orderRef);
};

#endif // ROUTES_H
32 changes: 32 additions & 0 deletions server/includes/webserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef WEBSERVER_H
#define WEBSERVER_H

#pragma once

#include "bankid.h"
#include <crow.h>
#include <crow/middlewares/cors.h>

class WebServer {
public:
WebServer();
~WebServer();

bool initialize();
void run(uint16_t port = 8080);
void shutdown();

private:
crow::App<crow::CORSHandler> m_app;
std::unique_ptr<BankID::Session> m_bankidSession;
BankID::API::AuthConfig m_authConfig;

void setupCORS();
void setupSSL();
void setupRoutes();
void printAvailableEndpoints() const;

bool m_isInitialized = false;
};

#endif // WEBSERVER_H
Loading