我正試圖開發一個應用程序鬆弛。 我想獲得代碼參數發送回答oauth流與鬆弛按鈕,但我不知道如何獲取參數。如何使用節點JS中的Slack獲取oAuth進程中的代碼參數?
其實我首先發送按鈕,然後有人可以點擊工具上的鬆弛通道的應用程序,然後將OAuth的流量重定向我到一個新的網頁的網址是哪 https://www.myappname.com/oauth/?code=[parameter我wan't獲得] &狀態=
問題是我的方法獲取代碼參數不等待重定向。
這裏是我的代碼:
var app = express();
var router = express.Router();
var port = process.env.PORT || 5000;
app.use('/', router);
recupCode = function(req, res, next){
console.log(req.params);
console.log('cb1 : le code est récupéré');
res.end();
};
//Fonctions de Callback
boutonSlack = function(req, res) {
res.send('<a href="https://slack.com/oauth/authorize?scope=incoming-webhook,'
+'&client_id='+process.env.CLIENT_ID+'">'
+'<img alt="Add to Slack" height="40" width="139"'
+'src="https://platform.slack-edge.com/img/add_to_slack.png" '
+'srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, '
+'https://platform.slack-edge.com/img/[email protected] 2x" /></a>');
console.log('cb0:le bouton slack s\'affiche');
router.get('/oauth/',recupCode);
};
router.get('/',boutonSlack);
app.listen(port, function() {
console.log('Ready');
});
謝謝你,我已經改變我的腳本,並瞭解其工作 – ghosteins
可以使用得到請求接入碼['req.query'] (http://expressjs.com/en/4x/api.html#req.query)。 – usandfriends