小编Man*_*r S的帖子

无法从 Heroku 上托管的 Express 应用程序设置 cookie

我在 Heroku 中托管了前端和后端。

  • 前端 - xxxxxx.herokuapp.com(反应应用程序)
  • 后端 - yyyyyy.herokuapp.com (express)

我正在尝试实施谷歌身份验证。从 Google OAuth2 获取令牌后,我尝试id_token通过 Express 应用程序在 cookie 中设置 和用户详细信息。

下面是我在后端的一段代码,

authRouter.get('/token', async (req, res) => {
    try {
        const result = await getToken(String(req.query.code))
        const { id_token, userId, name, exp } = result;
        const cookieConfig = { domain: '.herokuapp.com', expires: new Date(exp * 1000), secure: true }
        res.status(201)
            .cookie('auth_token', id_token, {
                httpOnly: true,
                ...cookieConfig

            })
            .cookie('user_id', userId, cookieConfig)
            .cookie('user_name', name, cookieConfig)
            .send("Login succeeded")
    } catch (err) {
        res.status(401).send("Login failed"); …
Run Code Online (Sandbox Code Playgroud)

cookies heroku setcookie node.js express

6
推荐指数
1
解决办法
3828
查看次数

实际交互与模拟 MockService 的预期交互不匹配

我是 python 和合同测试的新手。我正在尝试使用pact-python.

这是测试文件 test_posts_controller.py

import unittest
import atexit
from pact import Consumer, Provider, Term
import requests

pact = Consumer('Consumer').has_pact_with(Provider('Provider'))
pact.start_service()
atexit.register(pact.stop_service)

class GetPostsContract(unittest.TestCase):
    def test_get_all_posts(self):
        expected = {
            "userId": 1,
            "id": 1,
            "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
            "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
        }

        (pact
            .given('posts exist')
            .upon_receiving('a request for post by id')
            .with_request('GET', '/posts/1')
            .will_respond_with(200, body=expected)) …
Run Code Online (Sandbox Code Playgroud)

python-3.x pact pact-python

0
推荐指数
1
解决办法
2898
查看次数

标签 统计

cookies ×1

express ×1

heroku ×1

node.js ×1

pact ×1

pact-python ×1

python-3.x ×1

setcookie ×1