-
Notifications
You must be signed in to change notification settings - Fork 4k
[SECOAUTH-432] Support automatically destroying session on OAuth2 authorization server as soon as user redirected to client app #140
Comments
Great! This is exactly what I was looking for. |
Awesome Harleen. |
User switching or parallel logins (in the same browser) are a typical use case in businesses, so please provide an option for that. |
This worked wonderfully for me. When a user logs out of my ui service, they would just get logged back in automatically since their auth server session never expired. Now, when the user logs out of the ui server, they are brought to the auth server login page as expected. |
Outstanding--exactly what I needed! @harleen, when my people come to enslave your planet, you will not be harmed. |
Note that the aspect above will work, but it's neater to do the same thing with a @Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
...
endpoints.addInterceptor(new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView != null
&& modelAndView.getView() instanceof RedirectView) {
RedirectView redirect = (RedirectView) modelAndView.getView();
String url = redirect.getUrl();
if (url.contains("code=") || url.contains("error=")) {
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
}
}
}
});
} |
This interceptor jest fine when form login shows as result of standard process - ie. GET /oauth/authenticate which redirects to /login.html at which you log in. |
@tomasz-werminski that's expected though, I should think, because you aren't going to go through the OAuth2 protocol in that case. You just authenticated with the auth server, and now you could, for instance do some admin actions in there or something. It's nothing to do with OAuth2 at that point. Or am I missing something? |
@dsyer This is, of course, not a problem with this interceptor because its role is to invalidate session on oauth2 auhtentication process. But if your authorization server's only role is to authorize oauth clients above flow could be a problem (luckily it's no frequent). I was faced with such a flow so I've decided to describe it here because it's related to this topic, maybe it'll be helpful for somebody. As a workaround in login controller I check if /login.html call is "a part of normal flow", ie. whether in session is any saved request which triggered login proces. If not I make redirect to some configured URL. |
For newcomers, use the HandlerInterceptor approach instead of the Aspect's, because the last one will invalidate the session "always", even when user mistype his/her credentials. |
How this feature can be implemented with Single Sign on Kerberos/Spnego authentication. I am using pretty older version of zuul 1.1.0 . A example or pointer would be great. |
This might be a silly question . But how do I attach this handler interceptor via xml config? my organization uses <oauth2:authorization-server... and it's either that or I migrate everything to annotations. Currently I just placed a filter at the top of the chain that intercepts the auth code response and invalidates the session. However it seems a bit hacky to me. |
So what's the correct and better approach to fix this behaviour? The HandlerInterceptor or the SessionInvalidationOauth2GrantAspect? |
It'd be a nice feature to only maintain the session on the authorization server as long the user is granting approval to an oauth2 client, and no longer. This is useful for when your authorization server's sole role is for authorizing oauth2 clients, and nothing else. In this case, a longer lived session has no real value.
Also, if an oauth2 client wants to switch users for oauth2 access, it can't do so easily today. As long as the user's session is alive on the authorization server what will happen is as the client sends the user to /oauth/authorize, the client will be using the user's old session, and the client will be auto approved since it has a current access token for that user.
This feature should be configurable.
Currently I've accomplished this with use of aspects:
Comments:
david_syer on Mon, 30 Dec 2013 10:57:23 +0000
harleen on Mon, 30 Dec 2013 14:52:48 +0000
The text was updated successfully, but these errors were encountered: