2016-06-12 103 views
1

我正嘗試在同一個啓動中共同承載identityserver3和web api(用於使用持票人令牌的用戶管理)。但是,我收到以下錯誤: 任務被取消。 當嘗試撥打http://identity_local/core/.well-known/openid-configuration(identity_local指向本地主機)時,似乎任務取消在啓動時發生。任務被取消

我啓動如下:

app.Map("/core", idsrvApp => 
     { 
      var factory = new IdentityServerServiceFactory(); 
      factory.UserService = new IdentityServer3.Core.Configuration.Registration<IUserService, UserService>(); 
      factory.ScopeStore = new IdentityServer3.Core.Configuration.Registration<IScopeStore>(resolver => scopeStore); 
      var options = new IdentityServerOptions 
      { 
       SigningCertificate = Certificate.Load(), 
       IssuerUri = "http://identity_local/core", 
       PublicOrigin = "http://identity_local", 
       RequireSsl = false, //for now 
       Factory = factory, 
      }; 

      idsrvApp.UseIdentityServer(options); 
     }); 

     app.Map("/admin", adminApp => 
     { 
      adminApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
      { 
       Authority = "http://identity_local/core", 
       IssuerName = "identity_local", 
       ValidationMode = ValidationMode.Local, 
       RequiredScopes = new[] { "api", "roles" } 
      }); 

      adminApp.UseResourceAuthorization(new AuthorisationManager()); 

      var config = new HttpConfiguration(); 
      config.MapHttpAttributeRoutes(); 

      adminApp.UseCors(CorsOptions.AllowAll); 
      adminApp.UseWebApi(config); 

     }); 

有誰知道如果)有可能都在相同的啓動和b)如果是這樣,我做了什麼錯誤或我能做些什麼來有補救以上。

回答

6

在啓動時UseIdentityServerBearerTokenAuthentication試圖聯繫IdentityServer metatadata終點,但因爲服務器尚未運行它無法連接,從而錯誤。

對於這種情況,有一個叫DelayLoadMetadata延遲加載元數據在第一時間它的需要,直到標誌:https://identityserver.github.io/Documentation/docsv2/consuming/options.html

+0

你是我的英雄!我正在尋找一個星期的解決方案。而簡單地設置'DelayLoadMetadata = TRUE;在'IdentityServerBearerTokenAuthenticationOptions'沒有的伎倆。這應該definitley被標記爲正確的答案。實際上它應該在IdentityServer3的入門演練中。 – Michael