Single sign-on flow using JWT for cross domain authentication

Redirecting the user to the central authentication service when the user is not logged in to request credentials and issue a new authentication token is the common scenario in Single Sign On systems using well-known protocols like oauth2 or OpenId Connect However when this schema is used across domains the main drawback is that the … Read more

Spring security: adding “On successful login event listener”

You need to define a Spring Bean which implements ApplicationListener. Then, in your code, do something like this: public void onApplicationEvent(ApplicationEvent appEvent) { if (appEvent instanceof AuthenticationSuccessEvent) { AuthenticationSuccessEvent event = (AuthenticationSuccessEvent) appEvent; UserDetails userDetails = (UserDetails) event.getAuthentication().getPrincipal(); // …. } } Then, in your applicationContext.xml file, just define that bean and it will automatically … Read more

Sending cookie session id with Swagger 3.0

Swagger UI and Swagger Editor currently do not support sending cookies in “try it out” requests: https://github.com/swagger-api/swagger-js/issues/1163 As the developers explain, the issue is that it’s almost impossible to send arbitrary cookie data to a different origin from within the browser. SwaggerHub supports cookie auth and cookie parameters though. SwaggerHub sends “try it out” requests … Read more

How to use Windows Active Directory Authentication and Identity Based Claims?

Just hit AD with the username and password instead of authenticating against your DB // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.UserName); if (user != null && AuthenticateAD(model.UserName, model.Password)) { await SignInAsync(user, model.RememberMe); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError(“”, “Invalid username … Read more

REST API Token-based Authentication

Let me seperate up everything and solve approach each problem in isolation: Authentication For authentication, baseauth has the advantage that it is a mature solution on the protocol level. This means a lot of “might crop up later” problems are already solved for you. For example, with BaseAuth, user agents know the password is a … Read more

OWIN – Authentication.SignOut() doesn’t seem to remove the cookie

I had a similar problem for the past few days. Instead of Request.GetOwinContext().Authentication.authenticationManager.SignOut(); Use ONE(and only one) of these: Request.GetOwinContext().Authentication.SignOut(); Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); HttpContext.Current.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); This article explains why your cookies don’t get deleted: https://dzone.com/articles/catching-systemwebowin-cookie I know my answer isn’t the most research-based, but to tell you the truth, I just couldn’t find WHY my provided code examples … Read more

IIS7: Setup Integrated Windows Authentication like in IIS6

To enable the Windows Authentication on IIS7 on Windows 7 machine: Go to Control Panel Click Programs >> Programs and Features Select “Turn Windows Features on or off” from left side. Expand Internet Information Services >> World Wide Web Services >> Security Select Windows Authentication and click OK. Reset the IIS and Check in IIS … Read more