【问题标题】:Redirect policy in Azure API ManagementAzure API 管理中的重定向策略
【发布时间】:2023-05-10 17:07:01
【问题描述】:

Azure API 管理 (Azure APIM) 是否提供任何重定向 url 的方式,以便复制 Apigee RedirectToLoginPage 功能

【问题讨论】:

    标签: azure azure-api-management


    【解决方案1】:

    您可以使用在全局(所有 API)范围内设置的策略来执行此操作。

    <choose>
        <when condition="@(!context.Request.OriginalUrl.Host.Contains("redirect.com"))">
            <return-response>
                <set-status code="303" reason="See Other" />
                <set-header name="Location" exists-action="override">
                    <value>@("https://redirect.com/" + context.Request.OriginalUrl.Path + context.Request.OriginalUrl.QueryString)</value>
                </set-header>
            </return-response>
        </when>
    </choose>
    

    【讨论】:

      【解决方案2】:

      在撰写本文时,Azure APIM 级别不支持此功能。由于我将 IdentityServer 用于 Oauth2 安全性,因此我通过编写一个 owin/katana 身份验证中间件来实现这一点。 Anders Abel 有一个很棒的post about it

      【讨论】: