why my id_token seems to be lost when logout button is clicked

344 views Asked by At

I am using OpenIdConnect and needs to use an external login provider.

In the callback function of the authentication, I have these lines to get the id_token and needs to save it somewhere as it is requested by the login provider during signout process. So:

List<AuthenticationToken> tokens = context.Properties.GetTokens().ToList();

            tokens.Add(new AuthenticationToken()
            {
                Name = "id_token",
                Value = response.IdentityToken
            });
            context.Properties.StoreTokens(tokens);
    
            var id = new ClaimsIdentity(userInfo.Claims);
            principal.AddIdentity(id);

            await context.HttpContext.SignInAsync(principal, context.Properties);

So the id_token is saved here, and when the method is redirected to the login controller, and I do see the id_token in the AuthenticationToken property by calling this:

    var info = await _signInManager.GetExternalLoginInfoAsync();
    ////info.AuthenticationTokens does contain the id_token I need 

However, when the logout button is clicked,I needs to retrieve the id_token and sends to the loginProvider to end session with them. I tried following two methods and they both return null:

        var id_token_hint1 = await HttpContext.GetTokenAsync(IdentityConstants.ExternalScheme, "id_token");
        var id_token_hint1 = await HttpContext.GetTokenAsync("id_token");

So want am I doing wrong? Do I need to manually save this token into some cookie or something in the login controller? My understanding is that if I set options.SaveTokens = true; when setting up openIdConnect, it will save this automatically for me.

0

There are 0 answers