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

Flutter集成Supabase GitHub OAuth后,Deep Link无法跳转回应用

Flutter集成Supabase GitHub OAuth登录:Deep Link无法跳转回应用

问题描述

在Flutter应用中集成Supabase的GitHub OAuth登录,已按官方文档配置Deep Link,但GitHub认证完成后无法跳转回应用,要么停留在浏览器页面,要么显示错误提示。

已完成的配置步骤

1. AndroidManifest.xml配置

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
     <data android:scheme="mindq" android:host="github-login" />
</intent-filter>

2. Flutter登录函数实现

//! Sign in using GitHub OAuth
Future<void> signInWithGithub() async {
  try {
    await Supabase.instance.client.auth.signInWithOAuth(
      OAuthProvider.github,
      redirectTo: 'mindq://github-login',
      authScreenLaunchMode: LaunchMode.inAppWebView,
    );
  } on Exception catch (e) {
    debugPrint('[DEBUG] GitHub login failed: $e');

    Get.snackbar(
      'Login Failed',
      'GitHub login failed. Please try again.',
      snackPosition: SnackPosition.BOTTOM,
      backgroundColor: Colors.red,
      colorText: Colors.white,
      margin: const EdgeInsets.all(12),
      duration: const Duration(seconds: 3),
    );
  }
}

3. Supabase项目配置

在Authentication → URL Configuration中,已添加mindq://github-login

4. GitHub OAuth应用配置

已在GitHub开发者设置中正确配置Authorization Callback URL

5. Deep Link处理(使用App_Links包)

//! Start listening for incoming OAuth links
void deepLinkHandler() {
  _appLinks = AppLinks();
  _appLinks.uriLinkStream.listen((uri) {
    debugPrint('[DEBUG] OAuth Callback Received: $uri');

    if (uri.host == 'github-login' || uri.host == 'linkedin-login') {
      handleOAuthCallback(uri);
    }
  });
}

void handleOAuthCallback(Uri uri) async {
  try {
    await Supabase.instance.client.auth.getSessionFromUrl(uri);
    Get.offAllNamed(AppRoutes.mainApp);
  } catch (e) {
    debugPrint(e.toString());
    Get.snackbar(
      'Login Error',
      e.toString(),
      snackPosition: SnackPosition.BOTTOM,
    );
  }
}

问题现象

  • 登录成功后,浏览器无法自动跳转回应用,有时显示“页面未找到”错误
  • 按教程将GitHub OAuth应用的Homepage URL设为http://localhost:3000后,登录成功会被重定向到:

http://localhost:3000/?error=invalid_request&error_code=bad_oauth_callback&error_description=OAuth+state+parameter+missing

  • 浏览器显示:

“无法访问此网站 — localhost拒绝连接。”

已检查项

  • 登录时应用已安装并处于运行状态
  • 所有配置位置的redirectTo URL完全一致
  • 应用已获取网络权限
  • 使用真实物理设备进行测试

目标

实现GitHub登录成功后,自动通过Deep Link打开应用并跳转到mainApp页面

疑问

  1. 为何浏览器会重定向到localhost:3000而非触发Deep Link打开应用?
  2. 让Deep Link(mindq://github-login)正常唤起应用还缺少哪些关键配置?
  3. Supabase、Android或GitHub OAuth设置是否存在未完成的额外步骤?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 02:27:03