gpt4 book ai didi

node.js - 内部 OAuthError : Failed to obtain access token passport-instagram

转载 作者:搜寻专家 更新时间:2023-10-31 22:35:50 25 4
gpt4 key购买 nike

我在使用 passport-instagram 时遇到问题,我正在尝试在我的应用程序中实现 passport-instagram。每当我尝试使用 instagram 登录按钮登录时,我都会收到此错误:InternalOAuthError: Failed to obtain access token {no matching code}

这是代码

instagram.js(passport 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: "/"
})
}

路由器.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);

Instagram客户端(稍后会更改客户端和密码) enter image description here

现在我真的很困惑,我哪里做错了?也许这是显而易见的事情。

最佳答案

使用{failWithError: true}。例如:

passport.authenticate('oath2', {failWithError: true})

关于node.js - 内部 OAuthError : Failed to obtain access token passport-instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com