Skip to content

Continue client browser flow after User login from Identity Provider#12891

Open
cgeorgilakis wants to merge 2 commits intokeycloak:mainfrom
eosc-kc:RCIAM-1038-idpflow
Open

Continue client browser flow after User login from Identity Provider#12891
cgeorgilakis wants to merge 2 commits intokeycloak:mainfrom
eosc-kc:RCIAM-1038-idpflow

Conversation

@cgeorgilakis
Copy link
Copy Markdown
Contributor

@cgeorgilakis cgeorgilakis commented Jul 4, 2022

Closes #10250

Our implementation saves in AuthNotes of AuthenticationSessionModel all needed information for Client Browser Flow ( AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION of Client Browser Flow, flowid) before redirecting to Identity Provider login. After Identity Provider login has successfully finished, Keycloak can retrieve all needed information for Client Browser Flow from AuthNotes of AuthenticationSessionModel and proceed with Client Browser Flow.

Browser flows execution are now continuing after Identity Provider Login. That's why some tests need to be changed. Some changes indicate that Browser flow with Identity Provider login, is working well. I do not know if we need extra tests.
More tests failures are related with SamlClientBuilder and its related code. I do not know well test implementation of SamlClientBuilder in order to make appropriate changes in it or found possible errors in my code. Finally, KcOidcBrokerTest/KcSamlBrokerTest test method testPostBrokerLoginFlowWithOTP failure is strange.

@cgeorgilakis
Copy link
Copy Markdown
Contributor Author

cgeorgilakis commented Jul 4, 2022

I have added a check for CLIENT_AUTHENTICATION_EXECUTION and CLIENT_FLOW_ID not being null in method finishBrokerAuthentication of IdentityBrokerService for overcome errors and test failures. A warn is logged if at least one of CLIENT_AUTHENTICATION_EXECUTION and CLIENT_FLOW_ID is null. However, I am not sure if this check is needed and I do not understand why these variables are null in some cases. Is it related with test authedication flow implementation?

@cgeorgilakis
Copy link
Copy Markdown
Contributor Author

After rebasing some test methods( AbstractAdvancedBrokerTest.testPostBrokerLoginFlowWithOTP_bruteForceEnabled, KcOidcFirstBrokerLoginNewAuthTest.testReAuthenticateWithPasswordAndConditionalOTP_otpRequested, KcOidcFirstBrokerLoginNewAuthTest.testReAuthenticateWithPasswordOrOTP_otpConfigured_otpUsed) are failing. The problem is that otp is failed - added by loginTotpPage.login(totp.generateTOTP(totpSecret));. This happens when otp check is passed during IdP flow and Client flow requires otp again after successful IdP login. Why this happen? How can I fix it?

Moreover, SAML tests ( methods BrokerTest.testInResponseToSetCorrectly, BrokerTest.testLogoutPropagatesToSamlIdentityProvider) are not failing only for quarkus! Why? How can I fix it?

@cgeorgilakis
Copy link
Copy Markdown
Contributor Author

I have rebased it. Now, only failure tests is related to AbstractAdvancedBrokerTest.testPostBrokerLoginFlowWithOTP_bruteForceEnabled.

@mposolda mposolda self-assigned this Mar 13, 2024
@mposolda
Copy link
Copy Markdown
Contributor

Thanks a lot for the PR and sorry for it not yet being reviewed. We will try to review this once we have some time...

@trixpan
Copy link
Copy Markdown
Contributor

trixpan commented Apr 1, 2024

@mposolda any luck with this review?

@JSmith-Aura
Copy link
Copy Markdown

Any news on this? Just discovered this bug myself and am very keen to get it fixed....

@thereiam
Copy link
Copy Markdown

Same here. It would be amazing if this bug could be fixed! Thank you for all your great work.

@NicolasLiampotis
Copy link
Copy Markdown

Looking forward to the review whenever the team has a chance.

@tulequ
Copy link
Copy Markdown

tulequ commented May 2, 2024

Looking for this feature!!!

@piaoyunbo
Copy link
Copy Markdown

Any updates on this?Looking for this feature!!!

@JeffResc
Copy link
Copy Markdown

JeffResc commented Jun 6, 2024

Any updates on this? We are looking forward to this feature

@mixman68
Copy link
Copy Markdown

I need this feature too during my transition phase

Copy link
Copy Markdown
Contributor

@jirutka jirutka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix code-style

Comment on lines +940 to +947
String client_execution = authSession.getAuthNote(AuthenticationProcessor.CLIENT_AUTHENTICATION_EXECUTION);
String client_flow = authSession.getAuthNote(AuthenticationProcessor.CLIENT_FLOW_ID);
authSession.clearAuthNotes();
//keep CLIENT_AUTHENTICATION_EXECUTION and CLIENT_FLOW_ID if they exist
if (client_execution != null)
authSession.setAuthNote(AuthenticationProcessor.CLIENT_AUTHENTICATION_EXECUTION,client_execution);
if (client_flow != null)
authSession.setAuthNote(AuthenticationProcessor.CLIENT_FLOW_ID,client_flow);

This comment was marked as resolved.

Response response = processResult(result, true);
if (response == null) {
return continueAuthenticationAfterSuccessfulAction(model);
} else return response;

This comment was marked as resolved.


private void redirect(AuthenticationFlowContext context, String providerId) {
Optional<IdentityProviderModel> idp = context.getRealm().getIdentityProvidersStream()
Optional<IdentityProviderModel> idp = context.getRealm().getIdentityProvidersStream()

This comment was marked as resolved.

Comment on lines +108 to +110
//BROKER_USER_ID not null user have been login with Idp -> return success
if (context.getAuthenticationSession().getUserSessionNotes().get(Details.IDENTITY_PROVIDER_USERNAME) != null)
context.success();

This comment was marked as resolved.

}
if (!validateForm(context, formData)) {
return;
//BROKER_USER_ID not null user have been login with Idp -> return success

This comment was marked as resolved.

String execution = authSession.getAuthNote(AuthenticationProcessor.CLIENT_AUTHENTICATION_EXECUTION);
String flowId = authSession.getAuthNote(AuthenticationProcessor.CLIENT_FLOW_ID);

if (execution != null && flowId!=null) {

This comment was marked as resolved.

AuthenticationFlow authenticationFlow = processor.createFlowExecution(flowId, model);
//maybe find next flow
Response challenge = authenticationFlow.continueClientAuthAfterIdPLogin(model);
if (challenge != null) return challenge;

This comment was marked as resolved.

//return to client flow -> otp has been configured -> ask again
loginTotpPage.login(totp.generateTOTP(totpSecret));
waitForAccountManagementTitle();
AccountHelper.logout(adminClient.realm(bc.consumerRealmName()), bc.getUserLogin());

This comment was marked as resolved.

@cgeorgilakis cgeorgilakis force-pushed the RCIAM-1038-idpflow branch 3 times, most recently from aec0feb to 447fff5 Compare July 4, 2024 12:29
@cgeorgilakis
Copy link
Copy Markdown
Contributor Author

Fix code-style

@jirutka I have make code-style changes suggested and I have rebased it. Thanks.
@jirutka @mposolda could we proceed with reviewing this important bug fix for supporting client authentication flows with broker users?

Comment on lines +114 to +115
if (context.getAuthenticationSession().getUserSessionNotes().get(Details.IDENTITY_PROVIDER_USERNAME) != null)
context.success();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (context.getAuthenticationSession().getUserSessionNotes().get(Details.IDENTITY_PROVIDER_USERNAME) != null)
context.success();
if (context.getAuthenticationSession().getUserSessionNotes().get(Details.IDENTITY_PROVIDER_USERNAME) != null) {
context.success();
}

@jirutka
Copy link
Copy Markdown
Contributor

jirutka commented Jul 4, 2024

Unfortunately, I’m not familiar with the Keycloak codebase so I can’t tell whether it’s conceptually and logically correct. However, I’m also affected by this bug/flaw and look forward to the review.

@igor-nikiforov
Copy link
Copy Markdown

@mposolda just a friendly ping here.

@mposolda
Copy link
Copy Markdown
Contributor

@cgeorgilakis Sorry for the late review. Thanks for the PR. Unfortunately I think it makes sense even more complex and fragile (authentication flows are already quite fragile in general). And the test failures are also problematic...

I believe we can address your use-case (and hopefully most other use-cases as well) by some easier way. I've commented on the issue #10250 (comment) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to continue with "browser" authentication flow after Identity provider login