Changeset - 8c1c1970130e
[Not reviewed]
0 4 0
Jan Kaluza - 9 years ago 2016-01-07 21:08:38
jkaluza@redhat.com
Spectrum2 manager server: handle OAuth2
4 files changed with 22 insertions and 9 deletions:
0 comments (0 inline, 0 general)
libtransport/AdminInterface.cpp
Show inline comments
 
@@ -313,17 +313,12 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
	}
 
	else if (message->getBody().find("get_oauth2_url ") == 0) {
 
	else if (message->getBody().find("get_oauth2_url") == 0) {
 
		std::string body = message->getBody();
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 3) {
 
			std::string url = m_component->getFrontend()->getOAuth2URL(args);
 
			message->setBody(url);
 
		}
 
		else {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
		std::string url = m_component->getFrontend()->getOAuth2URL(args);
 
		message->setBody(url);
 
	}
 
	else if (message->getBody() == "registration_fields") {
 
		std::string fields = m_component->getFrontend()->getRegistrationFields();
spectrum/src/frontends/slack/SlackUserRegistration.cpp
Show inline comments
 
@@ -62,7 +62,7 @@ SlackUserRegistration::~SlackUserRegistration(){
 
}
 

	
 
std::string SlackUserRegistration::createOAuth2URL(const std::vector<std::string> &args) {
 
	std::string redirect_url = "http://slack.spectrum.im/auth/" + CONFIG_STRING(m_config, "service.jid");
 
	std::string redirect_url = "http://slack.spectrum.im/oauth2/" + CONFIG_STRING(m_config, "service.jid");
 
	OAuth2 *oauth2 = new OAuth2(CONFIG_STRING_DEFAULTED(m_config, "service.client_id",""),
 
						  CONFIG_STRING_DEFAULTED(m_config, "service.client_secret",""),
 
						  "https://slack.com/oauth/authorize",
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -16,6 +16,10 @@
 

	
 
static struct mg_serve_http_opts s_http_server_opts;
 

	
 
static int has_prefix(const struct mg_str *uri, const char *prefix) {
 
	size_t prefix_len = strlen(prefix);
 
	return uri->len >= prefix_len && memcmp(uri->p, prefix, prefix_len) == 0;
 
}
 

	
 
static std::string get_http_var(const struct http_message *hm, const char *name) {
 
	char data[4096];
 
@@ -551,6 +555,13 @@ void Server::serve_instances_register(struct mg_connection *conn, struct http_me
 
			int type = (int) TYPE_STRING;
 
			m_storage->updateUserSetting(info.id, instance, value);
 
		}
 

	
 
		response = send_command(instance, "get_oauth2_url " + jid);
 
		if (!response.empty()) {
 
			redirect_to(conn, hm, response.c_str());
 
			return;
 
		}
 

	
 
		redirect_to(conn, hm, "/instances");
 
	}
 

	
 
@@ -649,6 +660,10 @@ void Server::serve_instances(struct mg_connection *conn, struct http_message *hm
 
	print_html(conn, hm, html);
 
}
 

	
 
void Server::serve_oauth2(struct mg_connection *conn, struct http_message *hm) {
 
	std::cout << "OAUTH2 handler\n";
 
}
 

	
 
void Server::event_handler(struct mg_connection *conn, int ev, void *p) {
 
	struct http_message *hm = (struct http_message *) p;
 

	
 
@@ -684,6 +699,8 @@ void Server::event_handler(struct mg_connection *conn, int ev, void *p) {
 
		serve_users_add(conn, hm);
 
	} else if (mg_vcmp(&hm->uri, "/users/remove") == 0) {
 
		serve_users_remove(conn, hm);
 
	} else if (has_prefix(&hm->uri, "/oauth2") == 0) {
 
		serve_oauth2(conn, hm);
 
	} else {
 
		mg_serve_http(conn, hm, s_http_server_opts);
 
	}
spectrum_manager/src/server.h
Show inline comments
 
@@ -72,6 +72,7 @@ class Server {
 
		void serve_logout(struct mg_connection *conn, struct http_message *hm);
 
		void serve_onlineusers(struct mg_connection *conn, struct http_message *hm);
 
		void serve_cmd(struct mg_connection *conn, struct http_message *hm);
 
		void serve_oauth2(struct mg_connection *conn, struct http_message *hm);
 
		void print_html(struct mg_connection *conn, struct http_message *hm, const std::string &html);
 
		std::string send_command(const std::string &jid, const std::string &cmd);
 

	
0 comments (0 inline, 0 general)