【问题标题】:Flutter app: How to implement a proper logout function?Flutter app:如何实现正确的注销功能?
【发布时间】:2020-06-27 17:36:04
【问题描述】:

我有一个使用 Azure B2C 身份验证的颤振应用程序。为了实现这一点,我使用了颤振的 appAuth 包。登录过程正常,但 appAuth 不提供注销功能。登录后,我得到一个访问令牌。到目前为止,我的注销是删除此访问令牌。

问题是,Azure 要求登录用户流中的 Web 应用会话生命周期至少为 15 分钟。这意味着:如果用户在 15 分钟内登录和退出,他将自动重新登录。这使得其他用户无法登录。

我希望通过真正的注销来解决此问题,而不是仅删除访问令牌。在Azure Active Directory documentation 中找到以下代码行。但我无法让它运行。对注销功能有什么建议吗?

GET https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/logout?post_logout_redirect_uri=https%3A%2F%2Fjwt.ms%2F

【问题讨论】:

    标签: azure flutter oauth-2.0 jwt azure-ad-b2c


    【解决方案1】:

    我按照以下来源使用 David White 编写的 app auth 实现了以下注销功能。

    Future<void> _logOut() async {
        try {
          //for some reason the API works differently on iOS and Android
          Map<String, String> additionalParameters;
          if (Platform.isAndroid) {
            //works on Android but will miss p parameter when redirected back to authorize on iOS
            additionalParameters = {
              "id_token_hint": _idToken,
              "post_logout_redirect_uri": _redirectUrl
            };
          } else if (Platform.isIOS) {
            // with p parameter when redirected back to authorize on iOS
            additionalParameters = {
              "id_token_hint": _idToken,
              "post_logout_redirect_uri": _redirectUrl,
              'p': '<tenantID>'
            };
          }
          await appAuth.authorizeAndExchangeCode(
            AuthorizationTokenRequest(
              _clientId,
              _redirectUrl,
              promptValues: ['login'],
              discoveryUrl: _discoveryURL,
              additionalParameters: additionalParameters,
              scopes: _scopes,
            ),
          );
        } catch (e) {
          print(e);
        }
        setState(() {
          _jwt = null;
        });
      }
    

    来源:https://www.detroitdave.dev/2020/04/simple-azure-b2c-flutter.html

    【讨论】:

      猜你喜欢
      • 2018-08-04
      • 2019-11-20
      • 1970-01-01
      • 2011-05-09
      • 2010-10-17
      • 2019-03-12
      • 1970-01-01
      • 2011-05-24
      • 2011-12-16
      相关资源
      最近更新 更多