identityServer4 javascript CRO请求

identityServer4 javascript CRO请求,javascript,identityserver4,Javascript,Identityserver4,我使用identityServer4并配置一个简单的客户端: public static IEnumerable<Client> Clients => new List<Client> { new Client { ClientId="client", AllowedGrantTypes =Gra

我使用identityServer4并配置一个简单的客户端:

    public static IEnumerable<Client> Clients =>
        new List<Client>
        {
            new Client
            {
                ClientId="client",
                AllowedGrantTypes =GrantTypes.ClientCredentials,
                ClientSecrets={
                new Secret("test".Sha256())
                },
                AllowedCorsOrigins = {
                    "http://192.168.0.105:8080",
                    "http://localhost:5001"
                },
                AllowedScopes={ "api1"}
            }
        };
}
但飞行前返回401:
API与IdentityServer在同一应用程序中吗

您在客户端配置中设置的AllowedCorsOrigins仅适用于CORS对IdentityServer本身的请求。如果你有自己的API,你需要自己设置CORS

  var url = "http://localhost:5001/test/get";
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url);
  xhr.onload = function() {
    console.log(xhr.responseText);
  };
  xhr.setRequestHeader("Authorization", "Bearer mytoken");
  xhr.send();