Browse Source

[bugfix] slack auth & connect

B Thibault 8 years ago
parent
commit
b3347c0a5d
2 changed files with 5 additions and 9 deletions
  1. 1 1
      srv/src/controller/accountController.js
  2. 4 8
      srv/src/slack.js

+ 1 - 1
srv/src/controller/accountController.js

@@ -16,7 +16,7 @@ module.exports.AccountController = {
         } else if (req.urlObj.urlParts[1] === "addservice") {
             switch (req.urlObj.urlParts[2]) {
                 case "slack":
-                    Slack.getOauthToken(req.urlObj.queryTokens.code, (teamName, teamId, token) => {
+                    Slack.getOauthToken(req.urlObj.queryTokens.code, config.rootUrl +"account/addservice/slack", (teamName, teamId, token) => {
                         if (token) {
                             req.account.edit().addService("Slack", teamName, teamId, token);
                             accountManager.save(req.account);

+ 4 - 8
srv/src/slack.js

@@ -351,9 +351,8 @@ Slack.prototype.close = function() {
 };
 
 Slack.getUserId = function(code, redirectUri, cb) {
-    Slack.getOauthToken(code, redirectUri, (token) => {
-        if (token) {
-            httpsRequest(SLACK_ENDPOINT+GETAPI.identityEmail +"?token="+token,
+    Slack.getOauthToken(code, redirectUri, (teamName, userId, token) => {
+        httpsRequest(SLACK_ENDPOINT+GETAPI.identityEmail +"?token="+token,
             (status, resp) => {
                 if (status === 200 && resp.ok && resp.user && resp.user.email) {
                     cb(resp.user.id +'_' +resp.team.id);
@@ -361,17 +360,14 @@ Slack.getUserId = function(code, redirectUri, cb) {
                     cb(null);
                 }
             });
-        } else {
-            cb(null);
-        }
     });
 };
 
-Slack.getOauthToken = function(code, cb) {
+Slack.getOauthToken = function(code, redirectUri, cb) {
     httpsRequest(SLACK_ENDPOINT+GETAPI.oauth
         +"?client_id=" +config.services.Slack.clientId
         +"&client_secret=" +config.services.Slack.clientSecret
-        +"&redirect_uri=" +encodeURIComponent(config.rootUrl +"account/addservice/slack")
+        +"&redirect_uri=" +encodeURIComponent(redirectUri)
         +"&code=" +code,
     (status, resp) => {
         if (status === 200 && resp.ok) {