将https与Identity Server 4一起使用

时间:2017-07-04 02:43:25

标签: iis asp.net-core identityserver4

我已经按照这里的所有IS4教程进行了操作,但没有一篇强调如何在prod中使用https协议。我可能错过了一些东西但是当我使用https在IIS中部署我的IS4服务器时(使用我在IIS服务器上安装的证书),我再也无法调用tokenClient.RequestClientCredentialsAsync。它只返回错误=未授权 ErrorType = Http ,如图所示: enter image description here

我的IS4就是这样设置的

services.AddIdentityServer()
//.AddSigningCredential(cert)
.AddTemporarySigningCredential()...;

我也尝试使用相同的SSL证书但没有进展。

编辑(答案): Arghhh!我在部署的IIS站点上启用了基本身份验证,导致该错误,在禁用它之后,它按预期工作

1 个答案:

答案 0 :(得分:2)

AFAIK有两种方法可以添加https。在您的启动项目中,您可以在ConfigureServices方法

中添加以下代码
public void ConfigureServices(IServiceCollection services)
{
    //...
    services.AddMvc();

    if (!_env.IsDevelopment())
        services.Configure<Microsoft.AspNetCore.Mvc.MvcOptions>(o =>
            o.Filters.Add(new Microsoft.AspNetCore.Mvc.RequireHttpsAttribute()));
    //...
}

或者将RequireHttps属性添加到控制器中,再加上启用SSL