我在使用passport-instagram时遇到了麻烦,我试图在我的应用程序中实施passport-instagram。每当我尝试使用instagram登录按钮登录时,我都会收到此错误: InternalOAuthError:无法获取访问令牌{无匹配代码}
这是代码
instagram.js(护照Instagram配置文件)
var passport = require('passport');
var InstagramStrategy = require('passport-instagram').Strategy;
var User = require('../models/user');
var instaOpt = {
clientID: "aad229e3597643be92568acb46efb40d",
clientSecret: "5563070a33394e0fafada92a16ec2e71",
callbackURL: "http://localhost:8000/auth/instagram/callback"
};
var instagramInit = function(accessToken, refreshToken, profile, callback) {
User.findOne({ "instagram.id" : profile.id } , function(err, user) {
if (err) return callback(err);
if (user) {
return callback(null, user); // User already exist
}
var newUser = new User();
newUser.instagram.id = profile.id;
newUser.instagram.token = accessToken;
newUser.instagram.email = profile.email;
newUser.instagram.displayName = profile.displayName;
newUser.instagram.name = profile.name;
newUser.instagram.username = profile.username;
// newUser.instagram.picture = profile.picture;
newUser.save(function(err) {
if (err) {
throw err;
}
return callback(null, newUser);
});
});
}
passport.use(new InstagramStrategy(instaOpt, instagramInit));
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
module.exports = {
instagramLogin: passport.authenticate("instagram"),
instagramCallback: passport.authenticate("instagram", {
successRedirect: "/profile",
failureRedirect: "/"
})
}
router.js
var router = require('express').Router();
var authConfig = require('../config/auth-config');
var auth = require('../config/instagram');
router.get('/', function(req, res) {
res.render('index.ejs');
});
router.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
router.get('/profile', function(req, res) {
res.render('profile.ejs', {
user: req.user
});
});
router.get('/auth/instagram', auth.instagramLogin);
router.get('/auth/instagram/callback', auth.instagramCallback);
module.exports = router;
database.js(用户架构文件)
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
var Schema = mongoose.Schema;
var User = new Schema({
instagram: {
id: String,
token: String,
email: String,
displayName: String,
username: String,
name: String,
picture: String,
}
});
module.exports = mongoose.model('User', User);
现在我真的很困惑,我哪里做错了?也许这是明显的事情。
答案 0 :(得分:0)
使用{failWithError: true}
。例如:
passport.authenticate('oath2', {failWithError: true})
答案 1 :(得分:-1)
而是尝试创建新应用并使用新的客户端ID和密钥。当我使用facebook集成完成护照身份验证时,我遇到了同样的错误,然后我创建了一个新的Facebook应用程序ID并使用了新的密钥和客户端ID然后它工作。