Expo Go集成AWS Amplify Google登录遇OAuth配置异常
Expo Go + AWS Amplify Google登录:OAuth配置异常解决
调用await signInWithRedirect({ provider: 'Google' })时触发错误:
[OAuthNotConfigureException: oauth param not configured.]
当前配置文件(amplifyconfiguration.json)
{ "aws_project_region": "us-east-1", "aws_cognito_identity_pool_id": "{hidden}", "aws_cognito_region": "us-east-1", "aws_user_pools_id": "{hidden}", "aws_user_pools_web_client_id": "{hidden}", "oauth": { "domain": "us-east-1{hidden}.auth.us-east-1.amazoncognito.com" }, "federationTarget": "COGNITO_IDENTITY_POOLS", "aws_cognito_username_attributes": [ "EMAIL" ], "aws_cognito_social_providers": [ "GOOGLE" ], "aws_cognito_signup_attributes": [], "aws_cognito_mfa_configuration": "OFF", "aws_cognito_mfa_types": [], "aws_cognito_password_protection_settings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "REQUIRES_LOWERCASE", "REQUIRES_UPPERCASE", "REQUIRES_NUMBERS", "REQUIRES_SYMBOLS" ] }, "aws_cognito_verification_mechanisms": [ "EMAIL", "PHONE_NUMBER" ] }
问题原因
OAuth配置项不完整,AWS Amplify的OAuth模块需要redirectSignIn、redirectSignOut、responseType等必填字段,当前仅配置了domain,导致无法完成OAuth流程初始化。
修复步骤
补充OAuth配置字段
修改amplifyconfiguration.json中的oauth节点,添加必填项:"oauth": { "domain": "us-east-1{hidden}.auth.us-east-1.amazoncognito.com", "redirectSignIn": "exp://192.168.x.x:19000,exp://localhost:19000", "redirectSignOut": "exp://192.168.x.x:19000,exp://localhost:19000", "responseType": "code", "scope": ["email", "openid", "profile"] }redirectSignIn/redirectSignOut:填写Expo Go启动后终端显示的实际URL(如exp://192.168.1.100:19000),可同时添加本地和局域网地址。responseType:固定为code(对应Cognito授权码流,适配Expo环境)。scope:按需添加Google授权的权限范围。
同步Cognito用户池客户端配置
- 登录AWS控制台,进入Cognito用户池的「应用客户端」页面。
- 找到对应客户端,启用OAuth功能,选择「授权码授予」类型。
- 将
redirectSignIn和redirectSignOut中的URL分别添加到「回调URL」和「退出URL」列表。 - 确认已配置Google作为身份提供者,并填入正确的Google OAuth客户端ID与密钥。
验证配置一致性
确保本地amplifyconfiguration.json的OAuth配置与Cognito云端完全一致,若使用Amplify CLI管理,可运行amplify push同步修改。确认Expo环境地址
每次启动Expo Go后,检查终端显示的URL是否与配置中的redirectSignIn/redirectSignOut匹配,若地址变化需同步更新配置和Cognito客户端设置。
内容的提问来源于stack exchange,提问作者Renz Carillo
相关产品推荐
相关产品推荐

