【问题标题】:How to logout with openid_client after authentication via pkce in flutter app with keycloak using openid_client?如何在使用openid_client通过keycloak在flutter应用程序中通过pkce进行身份验证后使用openid_client注销?
【发布时间】:2022-01-18 16:51:49
【问题描述】:

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

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 使用 iOS 模拟器对 Flutter App 进行身份验证后 https://pub.dev/packages/openid_client 在某些时候我需要退出。

我可以这样做来获取注销 URL:

    String localhost = getLocalhost();

var uri = Uri.parse('http://$localhost:8180/auth/realms/REALM');

var clientId = 'pkce-client';

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

String idT = token.idToken.toCompactSerialization();
Credential credential = client.createCredential(
  tokenType: token.tokenType,
  refreshToken: token.refreshToken,
  idToken: idT,
);

 var url;
try {
  url = credential.generateLogoutUrl();
} catch (e) {
  print("Error during login (refresh) " + e.toString());

}
return url;

但是我如何使用 url 来注销呢?是否可以从 openid_client 完成?

提前致谢

【问题讨论】:

    标签: flutter keycloak openid logout


    【解决方案1】:

    将浏览器(Web 视图)重定向到该注销 url(注销 URL 不是 API 调用,因此您不能使用 XMLHttpRequest)。这将终止现有的 IdP 会话。当然,您还需要销毁您的应用已经拥有的任何本地令牌(访问/ID/刷新令牌)。

    【讨论】:

      【解决方案2】:

      IDP 应该有一个前端注销 url,您可以调用它来注销当前会话。它是直接从浏览器到 IDP 端点的调用。

      IDP 前端注销应终止会话,清除所有 cookie 但后端令牌(访问令牌、刷新令牌等)需要由您的应用程序清除。

      【讨论】:

        猜你喜欢
        • 2021-12-21
        • 2020-07-03
        • 2022-01-16
        • 1970-01-01
        • 2019-07-28
        • 2017-03-03
        • 2019-01-14
        • 2010-10-01
        • 2015-11-08
        相关资源
        最近更新 更多