【问题标题】:Azure Multi-tenant Web Api - can only have one AudienceAzure 多租户 Web Api - 只能有一个受众
【发布时间】:2018-01-07 07:37:21
【问题描述】:

我有一个需要 ida:Audience 参数来验证 JWT 的 OWIN Web Api

public static void ConfigureAuth(IAppBuilder app)
        {
            var tvps = new TokenValidationParameters
            {
                ValidAudience = Config.GetSetting("ida:Audience"),
                ValidateIssuer = false,
            };

这意味着我只能有一个可以连接到我的 Web Api 的客户端应用程序。似乎没有办法添加额外的受众。 因此,如果我想将其他客户端应用程序连接到我的 Web api,我必须更改 Audience.. 这没有多大意义……

【问题讨论】:

    标签: jwt azure-active-directory


    【解决方案1】:

    当您的 API 收到访问令牌时,该令牌中的 Audience Claim aud 应该用于您的 API。这意味着无论哪个客户端调用您的 Web API,受众声明都应该是相同的。

    如果您想唯一标识调用您的 Web api 的客户端应用程序,您应该查看 appid 声明。

    如果这有帮助,请告诉我!

    【讨论】:

    • 但是如果我想指定一个可以连接到我的 API 的客户端列表呢?
    • 您能否引用“该令牌中的 aud 应用于您的 API”的概念?
    • 您可以通过不同的方式仅指定选定数量的服务以调用您的 Web API。 imo 最直接的方法是让您的 API 检查令牌中的 appid 声明,并将其与允许调用您的 API 的服务白名单进行比较。让我给你一个aud声明的具体例子。当您获得 Microsoft Graph 的令牌时,无论您从哪个客户端调用,aud 声明都是 aud: https://graph.microsoft.com/。 Microsoft Graph 检查此属性以确保令牌用于此资源,否则拒绝任何令牌。
    • 这里是the specification 需要这个。 The "aud" (audience) claim identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the "aud" claim when this claim is present, then the JWT MUST be rejected.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 2020-06-28
    • 2019-03-11
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 2015-11-07
    相关资源
    最近更新 更多