Changeset - 57a0ebde1dd1
[Not reviewed]
0 1 0
Jan Kaluza - 10 years ago 2016-01-24 12:19:08
jkaluza@redhat.com
Slack: use client instead of rtm:start...
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
spectrum/src/frontends/slack/SlackUserRegistration.cpp
Show inline comments
 
@@ -47,49 +47,49 @@ namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "SlackUserRegistration");
 

	
 
SlackUserRegistration::SlackUserRegistration(Component *component, UserManager *userManager,
 
								   StorageBackend *storageBackend)
 
: UserRegistration(component, userManager, storageBackend) {
 
	m_component = component;
 
	m_config = m_component->getConfig();
 
	m_storageBackend = storageBackend;
 
	m_userManager = userManager;
 

	
 
}
 

	
 
SlackUserRegistration::~SlackUserRegistration(){
 
	
 
}
 

	
 
std::string SlackUserRegistration::createOAuth2URL(const std::vector<std::string> &args) {
 
	std::string redirect_url = "https://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",
 
						  "https://slack.com/api/oauth.access",
 
						  redirect_url,
 
						  "channels:read channels:write team:read im:read im:write chat:write:bot rtm:stream");
 
						  "channels:read channels:write team:read im:read im:write chat:write:bot client");
 
	std::string url = oauth2->generateAuthURL();
 

	
 
	m_auths[oauth2->getState()] = oauth2;
 
	m_authsData[oauth2->getState()] = args;
 

	
 
	return url;
 
}
 

	
 
std::string SlackUserRegistration::getTeamDomain(const std::string &token) {
 
	std::string url = "https://slack.com/api/team.info?token=" + Util::urlencode(token);
 

	
 
	rapidjson::Document resp;
 
	HTTPRequest req(HTTPRequest::Get, url);
 
	if (!req.execute(resp)) {
 
		LOG4CXX_ERROR(logger, url);
 
		LOG4CXX_ERROR(logger, req.getError());
 
		return "";
 
	}
 

	
 
	rapidjson::Value &team = resp["team"];
 
	if (!team.IsObject()) {
 
		LOG4CXX_ERROR(logger, "No 'team' object in the reply.");
 
		LOG4CXX_ERROR(logger, url);
 
		LOG4CXX_ERROR(logger, req.getRawData());
0 comments (0 inline, 0 general)