Commit 617b2288 by Czémán Arnold

Add BME login method

parent b872ee23
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include "occisession.h" #include "occisession.h"
#include <gq/Document.h>
#include <gq/Node.h>
using std::string; using std::string;
using nlohmann::json; using nlohmann::json;
using namespace OcciClient; using namespace OcciClient;
...@@ -40,7 +43,7 @@ void OcciSession::setCsrfTokenHeader(){ ...@@ -40,7 +43,7 @@ void OcciSession::setCsrfTokenHeader(){
this->connection->AppendHeader("X-CSRFToken", csrftoken); this->connection->AppendHeader("X-CSRFToken", csrftoken);
} }
OcciSession::OcciSession(const char* url, bool insecure, bool csrf){ OcciSession::OcciSession(const char* url, bool insecure, bool csrf):url(url){
RestClient::init(); RestClient::init();
this->connection = new RestClient::Connection(url); this->connection = new RestClient::Connection(url);
if (insecure) { if (insecure) {
...@@ -111,6 +114,35 @@ void OcciSession::circleOcciLogin(string username, string password){ ...@@ -111,6 +114,35 @@ void OcciSession::circleOcciLogin(string username, string password){
post("login/", json::parse(body)); post("login/", json::parse(body));
} }
void OcciSession::BMELogin(string username, string password, bool insecure){
std::string& sp_url = url;
auto con = new RestClient::Connection("");
if (insecure) {
con->SetHostVerify(false);
con->SetPeerVerify(false);
}
con->FollowRedirects(true);
auto r = con->get(sp_url + "/saml2/login/");
auto idp_auth_url = con->GetInfo().lastRequest.effectiveUrl;
std::string body = "j_username=" + username +
"&j_password=" + password;
con->setCookies(r.cookies);
r = con->post(idp_auth_url, body);
CDocument doc;
doc.parse(r.body.c_str());
CSelection c = doc.find("input[name=RelayState]");
auto RelayState = c.nodeAt(0).attribute("value");
c = doc.find("input[name=SAMLResponse]");
auto SAMLResponse = c.nodeAt(0).attribute("value");
RestClient::PostData data;
data["RelayState"] = RelayState;
data["SAMLResponse"] = SAMLResponse;
con->clearCookies();
r = con->post(sp_url + "/saml2/acs/", data);
this->connection->setCookies(r.cookies);
}
json OcciSession::queryInterface(){ json OcciSession::queryInterface(){
return get("-/"); return get("-/");
} }
...@@ -34,6 +34,7 @@ namespace OcciClient { ...@@ -34,6 +34,7 @@ namespace OcciClient {
private: private:
std::string url;
RestClient::Connection* connection = nullptr; RestClient::Connection* connection = nullptr;
bool csrftokenRequired = false; bool csrftokenRequired = false;
std::string csrfuri; std::string csrfuri;
...@@ -58,6 +59,8 @@ namespace OcciClient { ...@@ -58,6 +59,8 @@ namespace OcciClient {
void circleOcciLogin(std::string username, std::string password); void circleOcciLogin(std::string username, std::string password);
void BMELogin(std::string username, std::string password, bool insecure=false);
nlohmann::json queryInterface(); nlohmann::json queryInterface();
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment