Auth0 重定向到本地主机被浏览器阻止

问题描述 投票:0回答:1

我有一个由 Flutter 编写的 Windows 应用程序。我使用 Auth0 来处理登录/注销的事情。与 macOS 应用程序不同,Windows 应用程序无法直接从浏览器重定向,因此我在应用程序中创建了一个本地服务器来处理 auth0 回调。它在调试模式下工作正常。但是,当我通过命令

flutter build windows --release
构建发布版本时,它不起作用。

输入账号和密码后,浏览器阻止了重定向,如下图所示。

我猜这是cookies的安全问题。这是一个非常奇怪的问题,它在调试模式下工作正常,但在发布版本下不起作用。

下面是我的代码的一部分:

login() async {
  final url = Uri.https(auth0Uri, '/authorize', {
     'client_id': clientId,
     'audience': audience,
     'response_type': 'code',
     'redirect_uri': redirectUri,
  });

  launchUrl(url);

  await HttpServer.bind('localhost', 39456);

  await for (var request in localServer!) {
    handleRequest(request);
  }
}


handleRequest(HttpRequest request) {
  Uri uri = request.uri;

  // Get queryParameters from uri
  Map<String, String> queryParams = uri.queryParameters;

  // Get code
  String? code = queryParams['code'];

  debugPrint('code: $code');

  request.response.write("OK");

  request.response.close();
}
flutter windows desktop-application auth0
1个回答
0
投票

以下是一些排查和解决问题的建议:

验证证书处理: 确保您的 HTTPS 服务器(本地服务器)使用有效的 SSL 证书。在发布模式下,安全限制可能更严格,自签名证书或无效证书可能会导致问题。

将本地服务器的 http 改为 https: 由于这是用于身份验证目的的本地服务器,因此您可以在开发过程中尝试使用 HTTP 而不是 HTTPS。在生产环境中,您可能希望使用 HTTPS,但对于本地测试,HTTP 可能就足够了。

© www.soinside.com 2019 - 2024. All rights reserved.