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

Add OAUTH2 OIDC login support #1140

Merged
merged 16 commits into from
Apr 29, 2024
Merged

Add OAUTH2 OIDC login support #1140

merged 16 commits into from
Apr 29, 2024

Conversation

sahilph
Copy link
Contributor

@sahilph sahilph commented Apr 29, 2024

Description

This PR adds support for Single Sign-On (SSO) using OAUTH2 OpenID Connect (OIDC). This also supports auto-creation of the users if they do not exist in the database. This functionality can also be disabled. An error message will be given in that case.

An example docker-compose file has also been added.

Closes #994
Related Discussions #781, #467

If the OAUTH2 login is enabled a new button shows up on the login page as per the screenshot below:

image

Checklist:

  • I have read the Contribution Guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Contributor License Agreement

By submitting this pull request, I acknowledge and agree that my contributions will be included in Stirling-PDF and that they can be relicensed in the future under the MPL 2.0 (Mozilla Public License Version 2.0) license.

(This does not change the general open-source nature of Stirling-PDF, simply moving from one license to another license)

@sahilph sahilph requested a review from Frooodle as a code owner April 29, 2024 02:15
@Frooodle
Copy link
Member

Love the changes by the way! greatly appreciated

@sahilph
Copy link
Contributor Author

sahilph commented Apr 29, 2024

@Frooodle I have made the suggested changes. Please check.

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException , IOException{
OAuth2User oauthUser = (OAuth2User) authentication.getPrincipal();
if (userService.processOAuth2PostLogin(oauthUser.getAttribute("email"), applicationProperties.getSecurity().getOAUTH2().getAutoCreateUser())) {
Copy link
Member

Choose a reason for hiding this comment

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

Will email always be the username key, are there not usecases were OAuth passes an actually userID?

Copy link
Member

@Frooodle Frooodle Apr 29, 2024

Choose a reason for hiding this comment

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

Googling it seems that 'sub' might be better since emails can change, Are you able to test with this? (please correct me if i am wrong or downsides)

Actually i changed mind, this seems fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, no there is no standard userid claim supported by providers. Some return id claim (which is an integer) , some return sub claim (which is a 128-bit UUID). But everyone always support and return the email claim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems that 'sub' might be better since emails can change,

Yes, that's true, unfortunately sub the newer version of the unique-id claim. And not all providers support it. Some still use the old id claim

@Frooodle
Copy link
Member

Frooodle commented Apr 29, 2024

LGTM, i adding a quick question about email being the username if you could answer but all seems good

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException , IOException{
OAuth2User oauthUser = (OAuth2User) authentication.getPrincipal();
if (userService.processOAuth2PostLogin(oauthUser.getAttribute("email"), applicationProperties.getSecurity().getOAUTH2().getAutoCreateUser())) {
Copy link
Member

@Frooodle Frooodle Apr 29, 2024

Choose a reason for hiding this comment

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

Googling it seems that 'sub' might be better since emails can change, Are you able to test with this? (please correct me if i am wrong or downsides)

Actually i changed mind, this seems fine

@Frooodle Frooodle merged commit d9fa8f7 into Stirling-Tools:main Apr 29, 2024
3 checks passed
@sahilph sahilph deleted the oauth2-login branch April 29, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adding oauth2 / openid
2 participants