Flutter OpenID 使用 Keycloak 连接“无效参数:redirect_uri”

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

我正在 Flutter 中构建一个应用程序,并想使用 Keycloak (

quay.io/keycloak/keycloak:23.0.1
) 进行登录。 我使用 docker 在本地设置了 Keycloak,它可以工作。此外,使用 Keycloak 从应用程序登录效果非常好。 但是有效的重定向 URI 是
*
现在我想在其后面添加一个真实的 URI。我添加了以下行

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

App\frontend\android\app\build.gradle
和 Keycloak 中我添加了

但我收到错误消息

Invalid parameter: redirect_uri
。 我还尝试在位于
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
并启动 Keycloak,我使用
url_launcher: ^6.2.2

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

android flutter keycloak openid-connect
1个回答
0
投票

我发现问题了。 问题是我没有在验证函数中指定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;
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.