如何修复InternalOAuthError:无法获取通行证(instagram)的访问令牌

时间:2019-06-30 12:02:41

标签: node.js express passport.js instagram instagram-api

我已经使用github实现了通行证,但是对于Instagram-instagram,我遇到了这个问题。错误是InternalOAuthError:无法通过Strategy.OAuth2Strategy._createOAuthError获取访问令牌。授权后出现错误,因此我假设问题出在回调期间。

看看代码,请帮助我。

护照设置:

 passport.serializeUser((user, cb) => cb(null, user))
 passport.deserializeUser((obj, cb) => cb(null, obj))

 const callback = (accessToken, refreshToken, profile, cb) => cb(null, profile)
 passport.use(new InstagramStrategy({
        clientID: '06b648073d674f01b2c90f61664ae840',
        clientScret: 'd2c234b4dab344b78045ff67bffa40ca',
        callbackURL: 'https://127.0.0.1:8080/instagram/callback'
 }, callback))

路由:

const instagramAuth = passport.authenticate('instagram');

router.get('/instagram/callback', instagramAuth, const io = req.app.get('io')
    console.log('hi');
    const user = {
        name: 'Alex',
        // photo: req.user.photos[0].value
    }
    io.in(req.session.socketId).emit('instagram', user) //emit to client
    res.end())
}

服务器:

const passportInit = require('./config/passport-setup')
const key = require('./config/keys');
const authRouter = require('./routes/auth-routes')

const httpsOptions = {
    key: fs.readFileSync(path.join(__dirname, 'certs', 'server.key')),
    cert: fs.readFileSync(path.join(__dirname, 'certs', 'server.crt'))
}

const app = express();
const server = https.createServer(httpsOptions, app);

app.use(express.json());
app.use(passport.initialize());
passportInit()

app.use(cors({
    origin: 'http://localhost:3000'
}))

app.use(session({ 
    secret: key.sessionKey, 
    resave: true, 
    saveUninitialized: true 
}))

const io = socketIo(server);
app.set('io', io)

app.use('/', authRouter);

server.listen(8080, () => {
    console.log('listening...')
})

最后,错误消息发送到此链接: https://127.0.0.1:8080/instagram/callback?code=902c21e821ce41d3bfdcb69b770ca75e

通过阅读instagram api,上面的代码参数用于获取访问令牌,但我仍然没有得到它的作用,并且instagram说请求必须通过我已自签名证书的https进行,但我的chrome仍然没有相信这可能是个问题吗?

0 个答案:

没有答案