Todavía ha iniciado sesión en el sitio MVC, pero no puede llamar a la API web

Tengo un sitio ASP.NET MVC, un host IdentityServer4 y una API web.

Cuando inicio sesión en el sitio de MVC, usando un proveedor externo (Facebook), estoy conectado bien. Desde el sitio MVC también puedo consumir la API web correctamente.

Sin embargo, al día siguiente, todavía estoy conectado al sitio MVC, pero cuando intento acceder a la API web, obtengo una 'excepción no autorizada'.

Así que aunque todavía estoy conectado en el sitio MVC, ya no estoy autenticado para llamar a una API web desde el sitio MVC.

Me pregunto cómo manejar esta situación y cómo se debe configurar IdentityServer4.

¿Por qué sigo conectado al sitio de MVC un día después? ¿Cómo se puede configurar esto? ¿Por qué todavía no puedo llamar a la API web, si todavía estoy conectado al sitio MVC? ¿Puedo sincronizar los tiempos de vencimiento? ¿O cómo debo manejar esto?

La aplicación MVC está configurada como:

 services.AddAuthentication(options =>
        {
            options.DefaultScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc"; 
        })
        .AddCookie("Cookies")
        .AddOpenIdConnect("oidc", options =>
        {
            options.SignInScheme = "Cookies";
            options.Authority = mgpIdSvrSettings.Authority;
            options.RequireHttpsMetadata = false;                
            options.ClientId = mgpIdSvrSettings.ClientId;
            options.ClientSecret = mgpIdSvrSettings.ClientSecret; // Should match the secret at IdentityServer
            options.ResponseType = "code id_token"; // Use hybrid flow
            options.SaveTokens = true;                
            options.GetClaimsFromUserInfoEndpoint = true;                
            options.Scope.Add("mgpApi");
            options.Scope.Add("offline_access");                  
        });            

Así que está usando flujo híbrido.

In IdentityServer el cliente MVC está configurado como:

new Client
{
     EnableLocalLogin = false,

     ClientId = "mgpPortal",
     ClientName = "MGP Portal Site",
     AllowedGrantTypes = GrantTypes.Hybrid,

     // where to redirect to after login
     RedirectUris = mgpPortalSite.RedirectUris,

     // where to redirect to after logout
     PostLogoutRedirectUris = mgpPortalSite.PostLogoutRedirectUris,

     // secret for authentication
     ClientSecrets = mgpPortalSite.ClientSecrets.Select(cs => new Secret(cs.Sha256())).ToList(),

     AllowedScopes = new List<string>
     {
            IdentityServerConstants.StandardScopes.OpenId,
            IdentityServerConstants.StandardScopes.Profile,
            "mgpApi"
     },

     AllowOfflineAccess = true,                             
     RequireConsent = false,
},

Y finalmente la API web:

 services.AddAuthentication("Bearer")                
           .AddIdentityServerAuthentication(options =>
            {
                options.Authority = mgpIdSvrSettings.Authority;
                options.RequireHttpsMetadata = false;                    
                options.ApiName = mgpIdSvrSettings.ApiName;
                options.EnableCaching = true;
                options.CacheDuration = TimeSpan.FromMinutes(10);                    
            });

Respuestas a la pregunta(1)

Su respuesta a la pregunta