Search code examples
identityserver4aspnetboilerplate

token washed out after closing browser


I have integrated Identity server in my system and now I want to preserve Identity server token so that user do not have to re login after browser close.

Here is my code.

    //Identity server
    if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"]))
    {
        IdentityServerRegistrar.Register(services, _appConfiguration);

        //BHARAT : JWT Authentication Middleware
        services.AddAuthentication().AddIdentityServerAuthentication("IdentityBearer", options =>
        {
            options.Authority = _appConfiguration["App:ServerRootAddress"];
            options.RequireHttpsMetadata = false;
            options.ApiName = "default-api";
            options.ApiSecret = "def2edf7-5d42-4edc-a84a-30136c340e13".Sha256();
            options.CacheDuration = TimeSpan.FromMinutes(30);
            options.SaveToken = true;
        });
    }

I tried to follow this https://github.com/IdentityServer/IdentityServer3/issues/1379

This is snap of tokens in browser.

enter image description here

I have tried many other way to preserve the cookie/token but it's not working.

Do I have to add anything in my client side, I am using .net core 2.0 with angular version.


Solution

  • Try changing the condition in login.service.ts:

    // Before
    var tokenExpireDate = rememberMe
                        ? (new Date(new Date().getTime() + 1000 * expireInSeconds))
                        : undefined;
    
    // After
    var tokenExpireDate = expireInSeconds
                        ? (new Date(new Date().getTime() + 1000 * expireInSeconds))
                        : undefined;