代码之家  ›  专栏  ›  技术社区  ›  Noobie3001

如何在IdentityServer4中允许使用Google字体

  •  4
  • Noobie3001  · 技术社区  · 6 年前

    要在IdentityServer3中使用Google字体,以下内容安全策略从未起作用:

    <meta http-equiv="Content-Security-Policy" 
          content=" style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
                    font-src 'self' 'unsafe-inline' https://fonts.gstatic.com data:">
    

    相反,我们在idsrvApp中配置了CspOptions。使用有效的IdentityServer构造函数:

    CspOptions = new CspOptions {
        FontSrc = "https://fonts.gstatic.com",
        StyleSrc = "https://fonts.googleapis.com",
        Enabled = true
    }
    

    如何在IdentityServer4中配置CspOptions?我找不到它。

    1 回复  |  直到 6 年前
        1
  •  9
  •   Noobie3001    6 年前

    对于其他陷入困境的人,请访问SecurityHeadersAttribute。需要修改IdentityServer4快速启动文件附带的cs文件。添加以下行修复了它:

    var csp = "default-src 'self'; object-src 'none'; frame-ancestors 'none'; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self';";
    
    // These two lines enable google fonts
    csp += "font-src 'self' https://fonts.gstatic.com;";
    csp += "style-src 'self' https://fonts.googleapis.com;";
    

    该文件位于quickstart/SecurityHeadersAttribute中。cs公司