angularasp.net-coreidentityserver4oidc-client-js

AccessTokenLifeTime expiration- Identity server code flow


I have an ASP.NET Core application with IdentityServer4 for authentication and authorization.
I am using oidc-client with Angular 10 for the front-end.
The problem is my application never logs the user out even after the token is expired. it will be refreshed silently. My AccessTokenLifetime is set to 5 minutes. My CookieSlidingTime is set to 10 minute. Here is my code

    const idServerSettings = {
  authority: Constants.stsAuthority,
  client_id: Constants.clientId,
  scope: 'openid profile',
  response_type: 'code',
  redirect_uri: `${Constants.clientRoot}signin-callback`,
  post_logout_redirect_uri: `${Constants.clientRoot}signout-callback`,
  store: new WebStorageStateStore({ store: localStorage }),
  automaticSilentRenew: true,
  loadUserInfo: true
};

IdentityServer configuration

 new Client {
                ClientName="test",
                ClientId="client-spa",
                AllowedGrantTypes = GrantTypes.Code,
                AlwaysIncludeUserClaimsInIdToken = true,
                RedirectUris = new List<string>() { "https://localhost:44383/signin-callback" }, 
                PostLogoutRedirectUris = {"https://localhost:44383/signout-callback" },
                AllowedCorsOrigins = {  "https://localhost:44383" },
                AccessTokenLifetime = 60*5, // TODO
                AllowedScopes = {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    "propel-api"

                },
                RequireClientSecret=false
            }



   var builder = services.AddIdentityServer(options =>
        {
            options.Events.RaiseErrorEvents = true;
            options.Events.RaiseInformationEvents = true;
            options.Events.RaiseFailureEvents = true;
            options.Events.RaiseSuccessEvents = true;
            options.UserInteraction.LoginUrl = "/Account/Login";
            options.UserInteraction.LogoutUrl = "/Account/Logout";
            options.Authentication = new AuthenticationOptions()
            {
                CookieLifetime = TimeSpan.FromMinutes(10), 
                CookieSlidingExpiration = true,
                
            };

Solution

  • Silent refresh is because you have automaticSilentRenew set to true, per docs:

    automaticSilentRenew (boolean, default: false): Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration. The attempt is made as a result of the accessTokenExpiring event being raised.