Skip to content

Commit

Permalink
Fix / Allow callbacks in federated auth workflow (#481)
Browse files Browse the repository at this point in the history
* Only use a single instance of the login content resource loader

* Set same site cookie restrictions back to the HTTP default
  • Loading branch information
martin-traverse authored Dec 12, 2024
1 parent a27fd02 commit 2330dff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public class Http1LoginHandler extends ChannelInboundHandlerAdapter {

private static final int PENDING_CONTENT_LIMIT = 64 * 1024;

private static final LoginContent LOGIN_CONTENT = new LoginContent();

private final Logger log = LoggerFactory.getLogger(getClass());

private final AuthenticationConfig authConfig;
private final JwtProcessor jwtProcessor;
private final ILoginProvider loginProvider;
private final LoginContent loginContent;

private final String defaultReturnPath;

Expand All @@ -69,7 +70,6 @@ public Http1LoginHandler(
this.authConfig = authConfig;
this.jwtProcessor = jwtProcessor;
this.loginProvider = loginProvider;
this.loginContent = new LoginContent();

this.defaultReturnPath = authConfig.hasReturnPath()
? authConfig.getReturnPath()
Expand Down Expand Up @@ -243,7 +243,7 @@ private void serveLoginOk(ChannelHandlerContext ctx, HttpRequest request, Sessio
.map(s -> URLDecoder.decode(s, StandardCharsets.UTF_8))
.orElse(defaultReturnPath);

content = loginContent.getLoginOkPage(returnPath);
content = LOGIN_CONTENT.getLoginOkPage(returnPath);
headers = Http1Headers.fromGenericHeaders(content.headers());

AuthHelpers.addClientAuthCookies(headers, token, session);
Expand Down Expand Up @@ -271,7 +271,7 @@ private void serveLoginOk(ChannelHandlerContext ctx, HttpRequest request, Sessio

private void serveStaticContent(ChannelHandlerContext ctx, HttpRequest request) {

var content = loginContent.getStaticContent(request);
var content = LOGIN_CONTENT.getStaticContent(request);
var headers = Http1Headers.fromGenericHeaders(content.headers());

var response = new DefaultFullHttpResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class BuiltInLoginProvider implements ILoginProvider {

private static final Logger log = LoggerFactory.getLogger(BuiltInLoginProvider.class);

private final LoginContent loginContent;
private static final LoginContent LOGIN_CONTENT = new LoginContent();

private final IUserDatabase userDb;

public BuiltInLoginProvider(ConfigManager configManager) {

this.loginContent = new LoginContent();
this.userDb = SimpleLoginPlugin.createUserDb(configManager);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ private LoginResult checkLoginRequest(CommonHttpRequest request) {
if (usernameParam == null || usernameParam.size() != 1 ||
passwordParam == null || passwordParam.size() != 1) {

var loginFormPage = loginContent.getLoginFormPage();
var loginFormPage = LOGIN_CONTENT.getLoginFormPage();
return LoginResult.OTHER_RESPONSE(loginFormPage);
}

Expand All @@ -86,7 +86,7 @@ private LoginResult checkLoginRequest(CommonHttpRequest request) {
}
else {

var loginFormPage = loginContent.getLoginFormPage();
var loginFormPage = LOGIN_CONTENT.getLoginFormPage();
return LoginResult.OTHER_RESPONSE(loginFormPage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ void setClientCookie(

var cookie = new DefaultCookie(cookieName.toString(), cookieValue);

// TODO: Can we know the value to set for domain?

// Do not allow sending TRAC tokens to other end points
cookie.setSameSite(CookieHeaderNames.SameSite.Strict);
// Allow using the TRAC auth cookie when navigating in from other domains (this is the default)
// This is necessary to work as expected with some federated flows (and is also the HTTP default)
// TODO: This setting could be made a config parameter for the login auth provider
cookie.setSameSite(CookieHeaderNames.SameSite.Lax);

// Make sure cookies are sent to the API endpoints, even if the UI is served from a sub path
cookie.setPath("/");
Expand Down

0 comments on commit 2330dff

Please sign in to comment.