21

IdentityServer3 に対して問題なく認証している ASP.NET MVC アプリケーションがありますが、ユーザーが約 3 分後に AJAX 機能を続行する前に待機すると、ApiController の開始を使用するアプリケーションの Web API 部分が失敗します (3 分前はすべて正常に見えます)。 .

Chrome で表示されるエラーは次のとおりです。

XMLHttpRequest は https://test-auth.myauthapp.com/auth/connect/authorize?client_id=ecan-farmda …gwLTk5ZjMtN2QxZjUyMjgxNGE4MDg2NjFhZTAtOTEzNi00MDE3LTkzNGQtNTc5ODAzZTE1Mzgw を読み込めません。要求されたリソースに「Access-Control-Allow-Origin」ヘッダーがありません。したがって、オリジン ' http://test.myapp.com ' へのアクセスは許可されていません。

IE では、次のエラーが発生します。

SCRIPT7002: XMLHttpRequest: ネットワーク エラー 0x4c7、操作はユーザーによってキャンセルされました。

IdentityServer3 のログを見ると、次のようなエントリが表示されます。

2015-08-10 16:42 [警告] (Thinktecture.IdentityServer.Core.Configuration.Hosting.CorsPolicyProvider) CORS リクエストがパス: /connect/authorize from origin: http://test.myapp.comに対して作成されましたが、無効なため拒否されましたCORS パス

IdentityServer3 Web アプリケーションでは、クライアントに AllowedCorsOrigins を与えています。

Thinktecture.IdentityServer.Core.Models.Client client = new Thinktecture.IdentityServer.Core.Models.Client()
{
    Enabled = configClient.Enabled,
    ClientId = configClient.Id,
    ClientName = configClient.Name,
    RedirectUris = new List<string>(),
    PostLogoutRedirectUris = new List<string>(),
    AllowedCorsOrigins = new List<string>(),
    RequireConsent = false, // Don't show consents screen to user
    RefreshTokenExpiration = Thinktecture.IdentityServer.Core.Models.TokenExpiration.Sliding
};

foreach (Configuration.RegisteredUri uri in configClient.RedirectUris)
{
    client.RedirectUris.Add(uri.Uri);
}

foreach (Configuration.RegisteredUri uri in configClient.PostLogoutRedirectUris)
{
    client.PostLogoutRedirectUris.Add(uri.Uri);
}

// Quick hack to try and get CORS working
client.AllowedCorsOrigins.Add("http://test.myapp.com");
client.AllowedCorsOrigins.Add("http://test.myapp.com/"); // Don't think trailing / needed, but added just in case

clients.Add(client);

サービスを登録するときに、InMemoryCorsPolicyService を追加します。

app.Map("/auth", idsrvApp =>
{
    var factory = new IdentityServerServiceFactory();

    factory.Register(new Registration<AuthContext>(resolver => AuthObjects.AuthContext));
    factory.Register(new Registration<AuthUserStore>());
    factory.Register(new Registration<AuthRoleStore>());
    factory.Register(new Registration<AuthUserManager>());
    factory.Register(new Registration<AuthRoleManager>());

    // Custom user service used to inject custom registration workflow
    factory.UserService = new Registration<IUserService>(resolver => AuthObjects.AuthUserService);

    var scopeStore = new InMemoryScopeStore(Scopes.Get());
    factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
    var clientStore = new InMemoryClientStore(Clients.Get());
    factory.ClientStore = new Registration<IClientStore>(clientStore);

    var cors = new InMemoryCorsPolicyService(Clients.Get());
    factory.CorsPolicyService = new Registration<ICorsPolicyService>(cors);

    ...

    var options = new IdentityServerOptions
    {
        SiteName = "Authentication",
        SigningCertificate = LoadCertificate(),
        Factory = factory,
        AuthenticationOptions = authOptions
    };

    ...
});

IdentityServer3 のログ エントリには、「パスに対して行われた CORS リクエスト: / auth /connect/authorize」ではなく、「パスに対して行われた CORS リクエスト: /connect/authorize」と表示されていることに注意してください。しかし、IdentityServer3 のソース コードを調べると、これはおそらく問題ではないことがわかります。

おそらく、InMemoryCorsPolicyService が取得されていないのでしょうか?

ApiController と呼ばれる AJAX で機能しない理由について何か考えはありますか?

Thinktecture.IdevtityServer3 v1.6.2 は NuGet を使用してインストールされています。

アップデート

IdentityServer3 の開発者と話し合っていますが、まだ問題が解決されていません。それが役立つ場合:

https://github.com/IdentityServer/IdentityServer3/issues/1697

4

1 に答える 1