Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A task was canceled

I am trying to co-host identityserver3 and web api (for user management using Bearer tokens) in the same startup. However I get the following error: A task was canceled. It appears the task cancellation occurs on startup when trying to call http://identity_local/core/.well-known/openid-configuration (identity_local points to localhost).

My startup is as follows:

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);

        });

Does anyone know if a) it is possible to have both in the same startup and b) if so, what have I done wrong or what can I do to remedy the above.

like image 819
Manjhari Avatar asked Jan 27 '26 06:01

Manjhari


1 Answers

At startup time the UseIdentityServerBearerTokenAuthentication tries to contact the IdentityServer metatadata endpoint, but since the server is not yet running it can't connect, thus an error.

For this situation, there's a flag called DelayLoadMetadata to delay load the metadata until the first time it's needed: https://identityserver.github.io/Documentation/docsv2/consuming/options.html

like image 82
Brock Allen Avatar answered Jan 29 '26 12:01

Brock Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!