Flutter集成Appwrite实现Google/Facebook OAuth登录在Android端失败的问题求助
Flutter集成Appwrite实现Google/Facebook OAuth登录在Android端失败的问题求助
我正在尝试在我的Flutter Android应用中通过Appwrite实现第三方登录功能,但遇到了两种异常情况,而且Google和Facebook登录都存在完全相同的问题:
- 当不在
createOAuth2Session方法中传入success和failure回调URL时:Google/Facebook登录页面能正常打开,选择账号后会直接循环回到应用的登录页面,无法完成登录流程并停留在APP内 - 当传入自定义的success和failure回调URL时:选择账号后会抛出
AppwriteException,错误信息为Invalid OAuth2 Response. Key and Secret not available.,错误码500
我已经按照Appwrite官方文档的步骤完成了所有配置,但问题依然存在,希望能得到帮助。
相关代码与配置
1. OAuth登录核心逻辑(Controller类中)
Future<void> signInWithOAuth(OAuthProvider provider) async { try { print("Starting OAuth sign-in with provider: $provider"); final successUrl = 'appwrite-callback-<PROJECT_ID>://auth-callback/success'; final failureUrl = 'appwrite-callback-<PROJECT_ID>://auth-callback/failure'; await _account.createOAuth2Session( provider: provider, success: successUrl, failure: failureUrl, ); print("OAuth session created successfully. Checking auth status..."); await checkAuthStatus(); } on AppwriteException catch (e) { print("AppwriteException during OAuth: ${e.message}, code: ${e.code}"); if (e.response != null) { print("Full error response: ${e.response}"); } Get.snackbar('Error', e.message ?? 'OAuth sign-in failed'); } catch (e) { print("Unexpected error during OAuth: $e"); Get.snackbar('Error', 'An unexpected error occurred.'); } }
2. Appwrite Client初始化(main.dart中)
Get.put( Client() .setEndpoint(appwriteEndpoint) .setProject(appwriteProjectId) .setSelfSigned(status: true), );
3. AndroidManifest.xml中的Deep Link配置
<activity android:exported="true" android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:launchMode="singleTask"> <intent-filter android:label="flutter_web_auth_2"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="appwrite-callback-<PROJECT_ID>"/> </intent-filter> </activity>
已完成的验证配置
- 在Appwrite控制台中,已正确配置Google和Facebook的Client ID与Client Secret
- 在Google Cloud控制台、Facebook开发者平台中,已添加Appwrite官方提供的Redirect URI
- AndroidManifest.xml中配置的Deep Link Scheme与代码中使用的完全一致
- 测试环境下已开启Appwrite Client的Self Signed模式,Endpoint和Project ID均配置正确
我已经反复核对了Appwrite文档中的每一步,但问题依然存在,请问我哪里可能遗漏了配置,或者代码中存在什么潜在问题?
内容来源于stack exchange




