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

使用flutter_appauth实现Google授权时遭遇400 invalid_request错误

Flutter使用flutter_appauth实现Google授权时出现400 invalid_request错误

我在Flutter应用中使用flutter_appauth库实现Google授权功能,执行以下代码时触发了400 invalid_request错误:

authorizationTokenRequest = AuthorizationTokenRequest(
          clientId,
         'com.socialauthexample.mobile_app:/oauth2redirect',
          issuer: 'https://accounts.google.com',
          scopes: ['email', 'profile'],
        );

final AuthorizationTokenResponse? result =
          await _appAuth.authorizeAndExchangeCode(
        authorizationTokenRequest,
      );

错误截图:
错误截图1
错误截图2

排查与解决建议:

  • 核对重定向URI:登录Google Cloud控制台,找到对应OAuth 2.0客户端ID,确保配置的重定向URI和代码里的com.socialauthexample.mobile_app:/oauth2redirect完全一致,包括符号和大小写。注意要在对应平台(Android/iOS)的客户端配置里添加,不要加到Web应用的配置项中。
  • 确认客户端ID类型:Android应用必须用Android类型的客户端ID,iOS应用用iOS类型,不能使用Web客户端ID,否则会触发请求错误。
  • 检查项目API与授权屏幕:确保Google Cloud项目已启用Google People API(获取email、profile权限依赖此API),同时OAuth consent screen已完成配置,应用未发布的话要添加测试用户。
  • 平台端配置校验:
    • Android:在AndroidManifest.xml中添加匹配重定向URI的intent-filter,确保能捕获授权回调。
    • iOS:在Info.plist中配置CFBundleURLSchemes,将com.socialauthexample.mobile_app加入其中。

内容的提问来源于stack exchange,提问作者dr34d13h

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 17:15:14