Skip to content

Commit dcb59d1

Browse files
Brokered login session user support (#19)
* Add brokered login session user support * Delete unused code * Bump version
1 parent 8cd524e commit dcb59d1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'com.authsignal'
13-
version '2.1.3'
13+
version '2.1.4-beta.1'
1414

1515
repositories {
1616
mavenCentral()

app/src/main/java/com/authsignal/keycloak/AuthsignalAuthenticator.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,13 @@ private boolean handlePasswordAuthentication(AuthenticationFlowContext context)
7171
String username = formParams.getFirst("username");
7272
String password = formParams.getFirst("password");
7373

74-
if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
75-
logger.warning("Username or password is missing");
76-
context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, context.form()
77-
.setError("Invalid username or password")
78-
.createForm("login.ftl"));
79-
return false;
80-
}
81-
82-
UserModel user = context.getSession().users().getUserByUsername(context.getRealm(), username);
83-
84-
if (user == null) {
85-
user = context.getSession().users().getUserByEmail(context.getRealm(), username);
74+
// Use user from context if already set (e.g., after brokered login)
75+
UserModel user = context.getUser();
76+
if (user == null && username != null && !username.isEmpty()) {
77+
user = context.getSession().users().getUserByUsername(context.getRealm(), username);
78+
if (user == null) {
79+
user = context.getSession().users().getUserByEmail(context.getRealm(), username);
80+
}
8681
}
8782

8883
if (user == null) {
@@ -302,4 +297,4 @@ private Boolean enrolByDefault(AuthenticationFlowContext context) {
302297
.valueOf(config.getConfig().get(AuthsignalAuthenticatorFactory.PROP_ENROL_BY_DEFAULT));
303298
return enrolByDefault;
304299
}
305-
}
300+
}

0 commit comments

Comments
 (0)