我正在Flutter中构建一个应用程序,并希望使用Keycloak(quay.io/keycloak/keycloak:23.0.1)登录. 我用docker在本地设置了Keycloak,它工作正常.此外,从应用程序与Keycloak登录工作完美的罚款. But the Valid redirect URIs was 101 now I want to add a real URI behind it. I added the following line

    defaultConfig {
        ...
        manifestPlaceholders += [appAuthRedirectScheme: 'com.example.frontend']
    }

in App\frontend\android\app\build.gradle and in Keycloak I added enter image description here

但是我得到了错误消息Invalid parameter: redirect_uri. 我还try 在位于App\frontend\android\app\src\main\AndroidManifest.xml的Manifest.xml中添加deepLink

        <activity
            android:name=".MainActivity"
            ...

            <meta-data 
                android:name="flutter_deeplinking_enabled"
                android:value="true" />
            <intent-filter>
                <data
                    android:scheme="com.example.frontend"
                    android:host="frontend" />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

            </intent-filter>
        </activity>

但这对我来说仍然不起作用.

我的验证码如下所示:

Future<Credential?> authenticate(
    Client client, {
    List<String> scopes = const [],
  }) async {
    try {
      var authenticator = io.Authenticator(
        client,
        scopes: scopes,
        port: 4000,
        urlLancher: _urlLauncher,
      );

      return await authenticator.authorize();
    } catch (e) {
      log("Authorize error: $e");
      return null;
    }
  }

对于身份验证,我使用openid_client: ^0.4.8,要启动Keyloak,我使用url_launcher: ^6.2.2.

我也在互联网上搜索了一些链接,但它们对我来说不起作用,也许我错过了一些东西.

推荐答案

我发现问题了. 问题是我没有在authenticate函数中指定redirectUri.有了它工作得很好.

Future<Credential?> authenticate(
    Client client, {
    List<String> scopes = const [],
  }) async {
    try {
      var authenticator = io.Authenticator(
        client,
        scopes: scopes,
        port: 4000,
        urlLancher: _urlLauncher,
        redirectUri: Uri.parse('com.example.frontend'), // <--- added line
      );

      return await authenticator.authorize();
    } catch (e) {
      log("Authorize error: $e");
      return null;
    }
  }

Flutter相关问答推荐

Android Emulator冻结,但在调整窗口大小时解冻

CLI数据库连接后将SHA-1密钥添加到Firebase项目

Flutter 中的多页表现

如何实现Flutter 梳理机图像的小量移动

在Flutter 中更改扩展瓷砖的高度

Android Studio扩展控件上未加载Google map

怎么才能像这样在摆动着这些曲线呢?

如何将请求字段正确添加到DART多部分请求

如何在 Dart/Flutter 中克隆 Future

使用 flutter_svg 在 flutter 中的 Canvas 上绘制 SVG 图像

尽管设置了对齐方式,如何对齐列中的行?

Flutter如何在容器外创建环形进度条

更改底部导航栏下方 Flutter Snackbar 的位置

将状态维护到 asyncNotifier

如何使这种相机叠加在Flutter 中?

如何让小部件根据小部件的大小构建不同的布局?

如何在 cupertino switch flutter 中添加文本

gridview 的所有按钮都应该在Flutter 中适合其父容器

如何在没有上下文的情况下使用国际Flutter ?

Flutter 在滚动期间保持某些元素固定?