Add verify email required action for IdP email verification
Closes #26418 Signed-off-by: Lex Cao <lexcao@foxmail.com>
This commit is contained in:
parent
b99f45ed3d
commit
142c14138f
2 changed files with 40 additions and 0 deletions
|
@ -147,6 +147,8 @@ public class IdpEmailVerificationAuthenticator extends AbstractIdpAuthenticator
|
|||
.setAttribute(EmailTemplateProvider.IDENTITY_PROVIDER_BROKER_CONTEXT, brokerContext)
|
||||
.sendConfirmIdentityBrokerLink(link, expirationInMinutes);
|
||||
|
||||
authSession.addRequiredAction(UserModel.RequiredAction.VERIFY_EMAIL);
|
||||
|
||||
event.success();
|
||||
} catch (EmailException e) {
|
||||
event.error(Errors.EMAIL_SEND_FAILED);
|
||||
|
|
|
@ -953,6 +953,44 @@ public abstract class AbstractFirstBrokerLoginTest extends AbstractInitializedBa
|
|||
waitForPage(driver, "your email address has been verified already.", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkAccountByEmailVerificationToEmailVerifiedUser() {
|
||||
// set up a user with verified email
|
||||
RealmResource realm = adminClient.realm(bc.consumerRealmName());
|
||||
|
||||
UserResource userResource = realm.users().get(createUser("consumer"));
|
||||
UserRepresentation consumerUser = userResource.toRepresentation();
|
||||
|
||||
consumerUser.setEmail(bc.getUserEmail());
|
||||
consumerUser.setEmailVerified(true);
|
||||
userResource.update(consumerUser);
|
||||
configureSMTPServer();
|
||||
|
||||
// begin login with idp
|
||||
oauth.clientId("broker-app");
|
||||
loginPage.open(bc.consumerRealmName());
|
||||
logInWithBroker(bc);
|
||||
|
||||
// update account profile
|
||||
waitForPage(driver, "update account information", false);
|
||||
updateAccountInformationPage.assertCurrent();
|
||||
updateAccountInformationPage.updateAccountInformation("FirstName", "LastName");
|
||||
|
||||
// idp confirm link
|
||||
waitForPage(driver, "account already exists", false);
|
||||
idpConfirmLinkPage.assertCurrent();
|
||||
assertEquals("User with email user@localhost.com already exists. How do you want to continue?", idpConfirmLinkPage.getMessage());
|
||||
idpConfirmLinkPage.clickLinkAccount();
|
||||
|
||||
String url = assertEmailAndGetUrl(MailServerConfiguration.FROM, USER_EMAIL,
|
||||
"Someone wants to link your ", false);
|
||||
driver.navigate().to(url);
|
||||
|
||||
assertTrue(driver.getCurrentUrl().startsWith(getConsumerRoot() + "/auth/realms/master/app/"));
|
||||
assertTrue(adminClient.realm(bc.consumerRealmName()).users().get(consumerUser.getId()).toRepresentation().isEmailVerified());
|
||||
assertNumFederatedIdentities(consumerUser.getId(), 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refers to in old test suite: org.keycloak.testsuite.broker.AbstractFirstBrokerLoginTest#testLinkAccountByEmailVerificationResendEmail
|
||||
|
|
Loading…
Reference in a new issue