首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用使用openid_client的密钥罩通过pkce flutter应用程序进行身份验证

无法使用使用openid_client的密钥罩通过pkce flutter应用程序进行身份验证
EN

Stack Overflow用户
提问于 2021-11-08 19:50:54
回答 1查看 375关注 0票数 1

我有以下KeyCloak客户端配置,以使用pkce身份验证流程:

代码语言:javascript
复制
Realm: REALM

Client ID:              pkce-client
Client Protocol:        openid-connect
Access Type:            public
Standard Flow Enabled:  ON
Valid Redirect URIs:    http://localhost:4200/ 

Advanced Settings:
Proof Key for Code Exchange Code Challenge Method: S256

我尝试通过openid_client https://pub.dev/packages/openid_client使用iOS模拟器在flutter应用程序中进行身份验证,如下所示

代码语言:javascript
复制
  authenticate() async {

    var uri = Uri.parse('http://$localhost:8180/auth/realms/REALM');
    var clientId = 'pkce-client';
    var scopes = List<String>.of(['profile', 'openid']);
    var port = 4200;
    var redirectUri = Uri.parse(http://localhost:4200/);

    var issuer = await Issuer.discover(uri);
    var client = new Client(issuer, clientId);

    urlLauncher(String url) async {
      if (await canLaunch(url)) {
        await launch(url, forceWebView: true);
      } else {
        throw 'Could not launch $url';
      }
    }

    var authenticator = new Authenticator(
        client,
        scopes: scopes,
        port: port,
        urlLancher: urlLauncher,
        redirectUri: redirectUri,
    );

    var auth = await authenticator.authorize();
    var token= await auth.getTokenResponse();
    return token;
  }

但它只给我提供了这样的web视图:

运行KeyCloak的终端显示以下代码行:

代码语言:javascript
复制
INFO  [org.keycloak.protocol.oidc.endpoints.AuthorizationEndpointChecker] (default task-34) PKCE enforced Client without code challenge method.
WARN  [org.keycloak.events] (default task-34) type=LOGIN_ERROR, realmId=REALM, clientId=pkce-client, userId=null, ipAddress=127.0.0.1, error=invalid_request, response_type=code, redirect_uri=http://localhost:4200/, response_mode=query 

当使用Postman时,它起作用了,并为我提供了登录页面:

但我在那里有额外的参数,当使用openid_client时,我不知道将它们添加到Authenticator(..)中的什么地方,状态会自动添加。

代码语言:javascript
复制
state: <state>
code_challenge: <code-challenge>
code_challenge_method: S256 

我需要在openid_client方法中的某个地方添加这些code_challenge参数吗?

或者在使用App时需要更改重定向URL?我尝试了像这里提议的(https://githubmemory.com/repo/appsup-dart/openid_client/issues/32)那样的package_name,但也不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-09 06:44:44

请参阅the source code

代码语言:javascript
复制
      : flow = redirectUri == null
            ? Flow.authorizationCodeWithPKCE(client)
            : Flow.authorizationCode(client)

您已经指定了redirectUri,所以使用了authorizationCode flow。但在这种情况下,您需要authorizationCodeWithPKCE flow。所以只需确保redirectUri为空,并且将使用正确的PKCE流(具有正确的url参数,例如code_challenge)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69889165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档