Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more flexibility on when to display consent page #1552

Closed
wants to merge 1 commit into from

Conversation

MrJovanovic13
Copy link
Contributor

This PR fixes Issue-1541

Some things worth mentioning.

  1. The Predicate naming is too similar to the private method name, do you think we should find a different name?
  2. The private method is not static anymore since I am checking the predicate inside it and therefore i had to remove the static modifier and I've moved it above the other static methods in the file.
  3. I've added the logic in such a way that if predicate exists it will immediately exit according to its evaluation, without going through further checks(such as if authorization consent is enabled in client settings). I figured if someone sets the predicate they want it to have full control instead of still going through additional checks which are currently in place(scopes, previous consent etc.)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2024
@jgrandja
Copy link
Collaborator

jgrandja commented Mar 8, 2024

Thanks @MrJovanovic13. I will review this soon.

I'm trying to finish up gh-101 before we release 1.3.0-M3.

@jgrandja jgrandja self-assigned this Mar 8, 2024
@jgrandja jgrandja added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 8, 2024
@jgrandja jgrandja changed the title Issue-1541: Provide more flexibility on when to display consent page Provide more flexibility on when to display consent page Mar 8, 2024
Copy link
Collaborator

@jgrandja jgrandja left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @MrJovanovic13.

Please see review comments.

* {@link OAuth2AuthorizationCodeRequestAuthenticationContext#getRegisteredClient()} containing {@link RegisteredClient} used to make the request.
*
* @param requiresAuthorizationConsent the {@link Predicate} that determines if authorization consent is required.
* @since 1.2.3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update to 1.3

@@ -295,26 +339,6 @@ private static OAuth2TokenContext createAuthorizationCodeTokenContext(
return tokenContextBuilder.build();
}

private static boolean requireAuthorizationConsent(RegisteredClient registeredClient,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should keep this method and associated logic as-is but change the signature to:

private boolean requireAuthorizationConsent(OAuth2AuthorizationCodeRequestAuthenticationContext context)

We would also need to supply OAuth2AuthorizationCodeRequestAuthenticationContext with OAuth2AuthorizationRequest and OAuth2AuthorizationConsent.

This method would then be the default for:

private Predicate<OAuth2AuthorizationCodeRequestAuthenticationContext> requiresAuthorizationConsent;

Applications could then override this via setRequiresAuthorizationConsent().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.

Would you like if OAuth2AuthorizationRequest and OAuth2AuthorizationConsent got treated the same way as RegisteredClient by exposing getRegisteredClient() and a builder method registeredClient(RegisteredClient registeredClient) inside the OAuth2AuthorizationCodeRequestAuthenticationContext?

Or do you want just to use regular .put() and .get() for their supply & access?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed a commit with a refactor according to your comment.

I attempted to expose getter & builders methods in the OAuth2AuthorizationCodeRequestAuthenticationContext for OAuth2AuthorizationRequest and OAuth2AuthorizationConsent instead of the .put() and .get() approach. However that ended up breaking a lot of tests. If It's important to go in that direction, I will put some more effort into making that work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you like if OAuth2AuthorizationRequest and OAuth2AuthorizationConsent got treated the same way as RegisteredClient

Yes. We should make the getter @Nullable since it may be null when the authenticationValidator is called.

@MrJovanovic13 MrJovanovic13 force-pushed the issue-1541 branch 2 times, most recently from 4d4d80e to 8be811f Compare March 25, 2024 02:07
@MrJovanovic13 MrJovanovic13 requested a review from jgrandja March 30, 2024 21:41
@MrJovanovic13
Copy link
Contributor Author

Sorry for the slight delay, had a busy week.

I can squash the commits if you guys prefer that.

Copy link
Collaborator

@jgrandja jgrandja left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @MrJovanovic13. Please see review comments.

Also, please squash commits. Thanks.

@@ -63,6 +65,27 @@ public RegisteredClient getRegisteredClient() {
return get(RegisteredClient.class);
}

/**
* Returns the {@link OAuth2AuthorizationRequest oauth2 authorization request}.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add @since 1.3


/**
* Returns the {@link OAuth2AuthorizationConsent oauth2 authorization consent}.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add @since 1.3

* @return the {@link Builder} for further configuration
*/
@Override
public Builder put(Object key, Object value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed since it's inherited by AbstractBuilder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be removed since it's inherited by AbstractBuilder

I overrode this method as opposed to using the one in AbstractBuilder because the one in the AbstractBuilder does not accept null values and authorizationConsent can be null.

The alternative is to remove the not null assertion inside the AbstractBuilder, but it's inherited 5 times so I didn't want to cause potential issues in other builders.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If authorizationConsent or authorizationRequest is null it should not be passed into the builder so it's not an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If authorizationConsent or authorizationRequest is null it should not be passed into the builder so it's not an issue.

The authorizationConsent from authorizationConsentService.findById() is @Nullable.

So I added a null check which won't pass it into the builder if it's null. I got rid of the custom put() method.
Let me know if the solution is suitable.

* @param oAuth2AuthorizationRequest the {@link OAuth2AuthorizationRequest}
* @return the {@link Builder} for further configuration
*/
public Builder oAuth2AuthorizationRequest(OAuth2AuthorizationRequest oAuth2AuthorizationRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to authorizationRequest

* @param oAuth2AuthorizationConsent the {@link OAuth2AuthorizationConsent}
* @return the {@link Builder} for further configuration
*/
public Builder oAuth2AuthorizationConsent(OAuth2AuthorizationConsent oAuth2AuthorizationConsent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to authorizationConsent

@jgrandja jgrandja added this to the 1.3.0-RC1 milestone Apr 15, 2024
jgrandja added a commit that referenced this pull request Apr 15, 2024
@jgrandja
Copy link
Collaborator

Thanks for the updates @MrJovanovic13.

FYI, I added a polish commit to get this merged before tomorrow's release.

Thanks again!

@jgrandja jgrandja closed this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Provide more flexibility on when to display consent page
3 participants