【发布时间】:2017-02-12 16:13:59
【问题描述】:
我已经设置了一个 Azure 移动应用服务后端,并且有一个 Xamarin 应用正在使用它的服务。它使用 Azure 移动应用服务中的自定义身份验证来注册和验证应用的用户。
对于本地开发/调试应用程序的 OWIN 启动类包含一些代码来设置应用服务的身份验证选项,如https://azure.microsoft.com/nl-nl/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#local-debug 中所述。
在 Azure 中,移动应用服务的身份验证已启用(身份验证/授权),将“请求未通过身份验证时采取的操作”选项设置为“允许请求(无操作)”,以便应用程序处理请求身份验证。
这一切都按预期工作。
现在我们希望在我们的移动应用服务上支持自定义域,并支持当前的 ourmobileappservice.azurewebsites.net 域。我们已经配置了自定义域,配置了它的 SSL 证书并且一切正常。新令牌以自定义域作为受众/发行者发行,并且也在此庄园中得到验证。
但是,当以 ourmobileappservice.azurewebsites.net 作为受众/发行者发行令牌时,令牌验证期间会被拒绝。似乎只允许我们的自定义域作为有效受众。
对于本地开发,我们指定app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { ... }),同时设置ValidAudiences 属性。所以我也想在 Azure 环境中使用这个设置,这样我们就可以指定多个有效的受众来进行令牌验证。 注意:AppServiceAuthenticationOptions 当然与本地开发不同,例如SigningKey 来自 Azure 的环境变量)。
不幸的是,Azure 似乎根本不使用它。它仍然以完全相同的方式失败。如您所见,只有自定义域被指定为有效受众:
警告 JWT 验证失败:IDX10214:受众验证 失败的。观众:'https://ourmobileappservice.azurewebsites.net/'。 不匹配:validationParameters.ValidAudience: 'https://ourcustom.domain.com/' 或 validationParameters.ValidAudiences: 'null'。
如何使用自定义身份验证设置配置 Azure 移动应用服务,使其有效受众支持自定义域作为以前的 ourmobileappservice.azurewebsites.net?
编辑
为 Azure 指定的有效受众如下:
public static void ConfigureMobileApp(IAppBuilder app)
{
...
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
SigningKey = Environment.GetEnvironmentVariable("WEBSITE_AUTH_SIGNING_KEY"),
ValidAudiences = new[] { "https://ourcustom.domain.com/", "https://ourmobileappservice.azurewebsites.net/" },
ValidIssuers = new[] { "https://ourcustom.domain.com/", "https://ourmobileappservice.azurewebsites.net/" },
TokenHandler = config.GetAppServiceTokenHandler()
});
...
}
【问题讨论】:
-
您是否将“ourcustom.domain.com”添加到“ValidAudiences”?
-
是的,在 ValidAudiences 中指定自定义域和 ourmobileappservice.azurewebsites.net。但是配置的 ValidAudiences 似乎没有得到兑现。
-
你能分享你用来设置“ValidAudiences”的代码吗?
-
代码见我帖子的编辑部分。
-
谢谢,我随便看看就回来了……
标签: azure authentication owin azure-mobile-services