Ошибка - не удалось найти токен запроса в сеансе - PullRequest
0 голосов
/ 30 октября 2019

Я получаю следующую ошибку в passport-twitter

Error: Failed to find request token in session
    at SessionStore.get (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/passport-oauth1/lib/requesttoken/session.js:13:44)
    at Strategy.OAuthStrategy.authenticate (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/passport-oauth1/lib/strategy.js:214:33)
    at Strategy.authenticate (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/passport-twitter/lib/strategy.js:87:40)
    at attempt (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/passport/lib/middleware/authenticate.js:361:16)
    at authenticate (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/passport/lib/middleware/authenticate.js:362:7)
    at Layer.handle [as handle_request] (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/express/lib/router/route.js:137:13)
    at noticeMiddleware (/Users/xxxx/Desktop/datingApp/backend-self/functions/src/api/social.f.js:38:3)
    at Layer.handle [as handle_request] (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/xxxx/Desktop/datingApp/backend-self/functions/node_modules/express/lib/router/route.js:137:13)

Где мой сеанс cookie выглядит следующим образом

app.use(cookieParser())
    app.use(
     session({
     name: '__session',
     secret: 'kkkkj9h9', // TODO: Move to ENV
     resave: false,
     saveUninitialized: false,
     cookie: {
        expires: 600000,
        secure: false
     },
    }))
    app.use(passport.initialize())
    app.use(passport.session())

И я вызываю промежуточное ПО для паспорта в обратном вызове, как это

app.get(`/twitter/callback`,noticeMiddleware,  passport.authorize('twitter), async (req, res) => {

В приведенном выше уведомлении noticeMiddleware. Я просто консоль веду пару вещей там

noticeMiddleware (req, res, next) {
        console.notice(req.headers.host)
        console.notice(config.TWITTER_REDIRECT_URL())
        next()
    }

Выше записано это

>  [2019-10-30T10:20:44.138Z] localhost:5001
>  [2019-10-30T10:20:44.138Z] http://localhost:5001/xyz/us-central1/social/twitter/callback

И вот как выглядит моя паспортная стратегия

passport.use(
    new TwitterStrategy(
        {
            consumerKey: config.TWITTER_CONSUMER_KEY,
            consumerSecret: config.TWITTER_APP_SECRET,
            callbackURL: config.TWITTER_REDIRECT_URL()
        },
        async (accessToken, tokenSecret, profile, done) => {
            done(null, { accessToken, tokenSecret })
        }
    )
)

Можеткто-то поможет мне выяснить, почему я получаю Error: Failed to find request token in session

...