简体   繁体   English

Twitter Oauth Node.js Express console.log 未显示

[英]Twitter Oauth Node.js Express console.log not showing

I am using the following code to implmenet twitter Oauth in node.js.我正在使用以下代码在 node.js 中实现 twitter Oauth。 The token and tokenSecret are not showing up in the console.令牌和 tokenSecret 未显示在控制台中。

Everything else is working correctly, like the login, authentication, and callback functions.其他一切都正常工作,例如登录、身份验证和回调函数。

All I see in the console are the access logs like the following:我在控制台中看到的只是访问日志,如下所示:

GET / 304 197.320 ms - -获取 / 304 197.320 毫秒 - -
GET /stylesheets/style.css 304 2.092 ms - -获取 /stylesheets/style.css 304 2.092 毫秒 - -
GET /auth/twitter 302 404.252 ms - 0获取 /auth/twitter 302 404.252 毫秒 - 0

All I want to do is show the access token and access secret of the authenticated user.我要做的就是显示经过身份验证的用户的访问令牌和访问密码。

var createError = require('http-errors');
var express = require('express');
var session = require('express-session');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var passport = require('passport');
var TwitterStrategy = require('passport-twitter').Strategy;
var config = require('./config');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
  secret: 'secret-key',
  resave: true,
  saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());

// passport-twitter settings
passport.use(new TwitterStrategy({
    consumerKey: config.consumerKey,
    consumerSecret: config.consumerSecret,
    callbackURL: config.callbackURL
  },
  // After authentication

  function(token, tokenSecret, profile, done) {
    console.log("token: " + token);
    console.log("tokenSecret: " + tokenSecret);
    return done(null, profile);
  }
));
// Save to session
passport.serializeUser(function(user, done) {
  done(null, user);
});
passport.deserializeUser(function(user, done) {
  done(null, user);
});


app.use('/', indexRouter);
app.use('/success', usersRouter);
app.get('/auth/twitter', passport.authenticate('twitter'));
app.get('/auth/twitter/callback', 
  passport.authenticate('twitter', { failureRedirect: '/?auth_failed' }), 
  function (req, res) {
    res.redirect('/success');
  });




// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;

I set the callback url in the twitter app page to " http://localhost:3000/auth/twitter/callback " and it worked.我将 twitter 应用程序页面中的回调 url 设置为“ http://localhost:3000/auth/twitter/callback ”并且它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js + Vue.js:为什么vue.js文件中的console.log()没有显示在控制台中? - Node.js + Vue.js: why is console.log() in vue.js files not showing in console? 节点js console.log没有显示任何内容 - Node js console.log is not showing anything Node.js / Express不输出console.log,highcharts.js给出了未定义的错误 - Node.js/Express not outputting console.log, highcharts.js giving undefined error 为什么我的 node.js 表达代码不调用 console.log()? - Why does my node.js express code not call console.log()? Object 是未定义的,但是当我 console.log 他们总是“有效” Node.js 表达 - Object is undefined, but when I console.log them always "works" Node.js express Node.js console.log vs console.info - Node.js console.log vs console.info Node.js 5.5.0 console.log将不会记录 - Node.js 5.5.0 console.log won't log 路由时 express.js 不显示 console.log 消息 - express.js not showing console.log message when routing 令牌错误:错误请求; 谷歌 OAuth2; Node.js 上的 Passport.js; 能够使用 console.log 数据,但是会出现错误 - TokenError: Bad Request; Google OAuth2; Passport.js on Node.js; Able to console.log data, however delivers error 如何在node.js中使用stack trace记录错误? - How to console.log an error with stack trace in node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM