I’m working on an ASP.Net MVC application and can’t get logout to work. How do I specify the client_id and id_token_hint when using UseOktaMvc? I’ve seen the other post about having an event handler when using app.UseOpenIdConnectAuthentication, but I can’t figure out how to specify an event handler when using UseOktaMvc.
Startup.cs
public class Startup
{
public void Configuration(IAppBuilder app)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls;
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOktaMvc(new OktaMvcOptions()
{
OktaDomain = ConfigurationManager.AppSettings["okta:OktaDomain"],
ClientId = ConfigurationManager.AppSettings["okta:ClientId"],
ClientSecret = ConfigurationManager.AppSettings["okta:ClientSecret"],
AuthorizationServerId = ConfigurationManager.AppSettings["okta:AuthorizationServerId"],
RedirectUri = ConfigurationManager.AppSettings["okta:RedirectUri"],
PostLogoutRedirectUri = ConfigurationManager.AppSettings["okta:PostLogoutRedirectUri"],
GetClaimsFromUserInfoEndpoint = true,
Scope = new List<string> { "openid", "profile", "email" },
});
}
}
Login method:
if (!HttpContext.User.Identity.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(
OktaDefaults.MvcAuthenticationType);
return new HttpUnauthorizedResult();
}
I’ve tried specifying them as follows in the signout but that doesn’t work -
props.Dictionary.Add("id_token_hint", SessionManager.OktaInfo.IdToken);
props.Dictionary.Add("client_id", SessionManager.OktaInfo.OktaClientId);
var authTypes = new string[] { CookieAuthenticationDefaults.AuthenticationType, OktaDefaults.MvcAuthenticationType };
HttpContext.GetOwinContext().Authentication.SignOut(props, authTypes);