You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用WireMock模拟Google OAuth2认证及Google Drive工作流时遭遇redirect_uri_mismatch错误的问题求助

使用WireMock模拟Google OAuth2认证及Google Drive工作流时遭遇redirect_uri_mismatch错误的问题求助

各位大佬好,我现在碰到一个棘手的问题:为了内部测试需求,我想用WireMock模拟整个Google Drive的工作流,不想使用真实的服务账号。我已经配置了几个WireMock的API请求模拟,但遇到了奇怪的状况。

我配置的WireMock端点

Auth端点

{
  "request": {
    "method": "GET",
    "urlPattern": ".*/o/oauth2/v2/auth.*",
    "headers": {
      "Host": {
        "equalTo": "accounts.google.com"
      }
    }
  },
  "response": {
    "status": 302,
    "headers": {
      "Location": "callbackurl"
    }
  }
}

Redirect端点

{
  "request": {
    "method": "GET",
    "urlPattern": ".*/suite/oauth/callback.*"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "callback is succesful"
  }
}

Token端点

{
  "request": {
    "method": "POST",
    "url": "/token",
    "headers": {
      "Host": {
        "equalTo": "oauth2.googleapis.com"
      }
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{ \"access_token\": \"your_access_token\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"refresh_token\": \"your_refresh_token\" }"
  }
}

测试情况与问题

  • 用Postman或者Python脚本直接请求这些端点时,一切都能正常工作,返回预期的响应。
  • 但当我在实际应用中开启WireMock代理后,问题就出现了:应用会打开Chrome的新标签页,然后抛出以下错误:

You can’t sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue. Learn more about this error
If you are a developer of this app, see error details.
Error 400: redirect_uri_mismatch

我确认应用请求的URL和Postman里测试的完全一致,唯一的区别就是应用是在新窗口中打开这个请求。有没有大佬能帮我分析下原因?

备注:内容来源于stack exchange,提问作者Mkrish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 08:42:59