使用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, );
错误截图:

排查与解决建议:
- 核对重定向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加入其中。
- Android:在
内容的提问来源于stack exchange,提问作者dr34d13h
相关产品推荐
相关产品推荐

