【问题标题】:Azure AD Logout URL not redirectingAzure AD 注销 URL 未重定向
【发布时间】:2017-08-29 09:23:12
【问题描述】:

我正在构建以下网址

https://login.microsoftonline.com/<tenantid>/oauth2/logout?client_id=<clientId>&post_logout_redirect_uri=<encodedurl>

看起来像

https://login.microsoftonline.com/f4aaf6e1-ffff-ffff-bb63-4e8ebf728113/oauth2/logout?client_id=f562b4e3-ffff-ffff-b4bb-49ca64216e75&post_logout_redirect_uri=https%3A%2F%2Fmyazureapp.azurewebsites.net

它会注销我,但不会将我重定向回我的应用程序

就像这个 URL 对 azure 所做的一样

https://login.microsoftonline.com/common/oauth2/logout?post_logout_redirect_uri=https%3a%2f%2fmanage.windowsazure.com%2fSignOut%2fComplete

我查看了建议的相关问题,并尝试了一些变体。

编辑原来是一个间歇性问题,我猜这是由于我在进行开发/测试周期时没有重置某些 cookie/其他状态。使用新的浏览器它可以工作。当它工作时,退出屏幕会显示类似“等一下,我们将您退出”然后它会重定向,当它不起作用时,屏幕会显示“您已退出,请关闭您的浏览器”

【问题讨论】:

    标签: azure azure-active-directory adal


    【解决方案1】:

    在您的 AD 应用程序中设置 Logout URL 属性。

    1. 登录AAD admin center portal
    2. 如图所示进入应用注册
    3. 选择您的 AD 应用程序
    4. 转到属性
    5. 更新您的预期应用程序注销重定向 URL,如图所示
    6. 保存

    【讨论】:

    • 我检查了这个,但我会仔细检查:)
    • 查看我的编辑,我已将此设置为空白并且可以正常工作。我正在使用 JWT 进行身份验证,所以当我退出时,我点击 Azure,然后点击清除 JWT 令牌的页面。
    • 我认为注销 URL 是 Azure 在另一个应用程序注销时告诉您的应用程序的方式,并且应该使用相同的令牌将注销传播到所有其他应用程序:docs.microsoft.com/bs-latn-ba/azure/active-directory/develop/…
    • 由于上面的示例使用localhost,请记住(在撰写本文时)Azure 门户不允许使用http://localhost 作为注销 URL,并且需要一个以开头的 URL https.
    【解决方案2】:

    我假设您正在使用 OpenIDConnect 流程并希望将用户注销。为了确保从 Azure AD 重定向到我们使用 post_logout_redirect_uri 参数指定的 URL,我们需要在 Azure 门户的应用注册的Reply URLs中进行注册。

    之后,我们还需要确保用户在 Azure AD 中成功登录。例如,我们先登录用户,然后再注销用户。这次重定向应该可以正常工作。然后我们再次发送退出请求,那么这次重定向将不起作用,因为用户已经退出。

    此外,通过 OpenIdConnect 流向end_session_endpoint 的请求无需提供client_id 参数。关于这个 OpenIdConnect 的更多细节,你可以参考下面的文档:

    Authorize access to web applications using OpenID Connect and Azure Active Directory

    【讨论】:

    • 我确实在我的 Reply URLs 中注册了该 URL,尽管我不确定注销过程是否需要它们(使用随机相同的原始 URL 进行测试并且它有效),例如,使用 AZURE 页面,您可以导航到 login.microsoftonline.com/common/oauth2/…(注意 X),它会注销,然后要求您签名,然后您会收到 404,因为 CompleteX 不存在。它确实需要是相同的来源,尽管您不能将其发送到谷歌,例如。也许来源与回复网址匹配
    • X 不会影响此行为,因为重定向仅由域确定。例如,如果将此 URL 替换为不正确的域,例如 http://test.com'(the browser determine the server by domain) it will stay on the sign-out page. And if you want after users sign-out it will redirect to the site https%3A%2F%2Fmyazureapp.azurewebsites.net`,则应将其重新设置为应用的 回复 URL。如果有帮助,请告诉我。
    • 通过将 URL 添加到回复 url,注销重定向开始工作。
    • @carraua 你能告诉我你输入的网址格式吗
    【解决方案3】:

    我也遇到了这个问题,对我有用的是:

    1. 我在属性中添加了我的注销 URL,以及回复 URL。
    2. 注销按钮具有以下href:
    https://login.windows.net/<tenant_id_of_your_app>/oauth2/logout?post_logout_redirect_uri=<logout_URL_of_your_app>/logout
    

    【讨论】:

    • 您对清单做了哪些更改?你能解释一下吗?
    【解决方案4】:

    使用 Python、Flask 和 MSAL 2.0,我做了以下工作:

    @app.route("/logout")
    def logout():
        logout_user()
        if session.get("user"):  # Used MS Login
            # Wipe out user and its token cache from session
            session.clear()
            # Also logout from your tenant's web session
            redirect(
                Config.AUTHORITY
                + "/oauth2/v2.0/logout"
                + "?post_logout_redirect_uri="
                + url_for("login", _external=True, _scheme="https")
            )
        app.logger.info("Logging user out.")
        return redirect(url_for("login"))
    

    在 Azure 门户中,我的端点配置如下:

    环境变量是这样配置的

    # Oauth - Azure Active Directory and MSAL
    export CLIENT_SECRET=<your-client-secret>
    export CLIENT_ID=<your-client-id>
    export REDIRECT_PATH=/getAToken
    export SESSION_TYPE=filesystem
    export AUTHORITY=https://login.microsoftonline.com/common
    export SCOPE=User.Read
    export SESSION_TYPE=filesystem
    

    config.py 文件

    import os
    
    from dotenv import load_dotenv
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    load_dotenv(os.path.join(basedir, ".env"))
    
    
    class Config(object):
        ### Info for MS Authentication ###
        ### As adapted from: https://github.com/Azure-Samples/ms-identity-python-webapp ###
        CLIENT_SECRET = os.environ.get("CLIENT_SECRET")
        # In your production app, Microsoft recommends you to use other ways to store your secret,
        # such as KeyVault, or environment variable as described in Flask's documentation here:
        # https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables
        # CLIENT_SECRET = os.getenv("CLIENT_SECRET")
        # if not CLIENT_SECRET:
        #     raise ValueError("Need to define CLIENT_SECRET environment variable")
    
        AUTHORITY = os.environ.get("AUTHORITY")  # For multi-tenant app, else put tenant name
        # AUTHORITY = "https://login.microsoftonline.com/Enter_the_Tenant_Name_Here"
    
        CLIENT_ID = os.environ.get("CLIENT_ID")  #
    
        REDIRECT_PATH = os.environ.get(
            "REDIRECT_PATH"
        )  #  Used to form an absolute URL; must match to app's redirect_uri set in AAD
    
        # You can find the proper permission names from this document
        # https://docs.microsoft.com/en-us/graph/permissions-reference
        SCOPE = [os.environ.get("SCOPE")]  # Only need to read user profile for this app
    
        SESSION_TYPE = os.environ.get(
            "SESSION_TYPE"
        )  # Token cache will be stored in server-side session
    

    【讨论】:

      【解决方案5】:

      下面的注销 url 对我有用,无需在 azure 应用程序中配置注销 URL。 [前频道登出网址]

      https://login.microsoftonline.com/{TenantID}/oauth2/logout?post_logout_redirect_uri={baseurlOfdWebsite}

      这里 baseurlOfdWebsite 应该是 URL 编码

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        • 2022-08-14
        • 1970-01-01
        • 1970-01-01
        • 2020-11-15
        • 1970-01-01
        • 2021-07-11
        相关资源
        最近更新 更多