-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6799e14
Somewhat working
sahilph 3e98119
Change Autocreate logic
sahilph 190407a
Add OAuth Error Message if Auto create Disabled
sahilph 7d56858
Display OAUTH2 username(email) in Account Settings
sahilph 12d76d4
Disable Change user/pass for Oauth2 user
sahilph 7b72df8
Hide SSO Button if SSO login Disabled
sahilph bca59ba
Remove some spaces and comments
sahilph 510b373
Add OAUTH2 Login example docker-compose file
sahilph 6928fa5
Add Some Comments
sahilph 0411e5c
Merge branch 'main' into oauth2-login
sahilph 9baf732
Hide Printing of Client secret
sahilph ca0f2e9
Remove OAUTH2 Beans
sahilph 2809b09
Add conditional annotation to Bean Creation
sahilph 51ef7b1
Update settings.yml.template
sahilph 2140368
Update messages_en_GB.properties
sahilph fc0964d
Merge branch 'oauth2-login' of https://github.com/sahilph/Stirling-PD…
sahilph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
exampleYmlFiles/docker-compose-latest-security-with-sso.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
version: '3.3' | ||
services: | ||
stirling-pdf: | ||
container_name: Stirling-PDF-Security | ||
image: frooodle/s-pdf:latest | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4G | ||
healthcheck: | ||
test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -q 'Please sign in'"] | ||
interval: 5s | ||
timeout: 10s | ||
retries: 16 | ||
ports: | ||
- 8080:8080 | ||
volumes: | ||
- /stirling/latest/data:/usr/share/tessdata:rw | ||
- /stirling/latest/config:/configs:rw | ||
- /stirling/latest/logs:/logs:rw | ||
environment: | ||
DOCKER_ENABLE_SECURITY: "true" | ||
SECURITY_ENABLELOGIN: "true" | ||
SECURITY_OAUTH2_ENABLED: "true" | ||
SECURITY_OAUTH2_AUTOCREATEUSER: "true" # This is set to true to allow auto-creation of non-existing users in Striling-PDF | ||
SECURITY_OAUTH2_ISSUER: "https://accounts.google.com" # Change with any other provider that supports OpenID Connect Discovery (/.well-known/openid-configuration) end-point | ||
SECURITY_OAUTH2_CLIENTID: "<YOUR CLIENT ID>.apps.googleusercontent.com" # Client ID from your provider | ||
SECURITY_OAUTH2_CLIENTSECRET: "<YOUR CLIENT SECRET>" # Client Secret from your provider | ||
PUID: 1002 | ||
PGID: 1002 | ||
UMASK: "022" | ||
SYSTEM_DEFAULTLOCALE: en-US | ||
UI_APPNAME: Stirling-PDF | ||
UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest with Security | ||
UI_APPNAMENAVBAR: Stirling-PDF Latest | ||
SYSTEM_MAXFILESIZE: "100" | ||
METRICS_ENABLED: "true" | ||
SYSTEM_GOOGLEVISIBILITY: "true" | ||
restart: on-failure:5 |
43 changes: 43 additions & 0 deletions
43
src/main/java/stirling/software/SPDF/config/security/CustomLogoutSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package stirling.software.SPDF.config.security; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import jakarta.servlet.http.HttpSession; | ||
import jakarta.servlet.ServletException; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.session.SessionRegistry; | ||
import org.springframework.security.core.session.SessionRegistryImpl; | ||
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; | ||
|
||
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler | ||
{ | ||
@Bean | ||
public SessionRegistry sessionRegistry() { | ||
return new SessionRegistryImpl(); | ||
} | ||
|
||
@Override | ||
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException | ||
{ | ||
HttpSession session = request.getSession(false); | ||
if (session != null) { | ||
String sessionId = session.getId(); | ||
sessionRegistry() | ||
.removeSessionInformation( | ||
sessionId); | ||
} | ||
|
||
if(request.getParameter("oauth2AutoCreateDisabled") != null) | ||
{ | ||
response.sendRedirect(request.getContextPath()+"/login?error=oauth2AutoCreateDisabled"); | ||
} | ||
else | ||
{ | ||
response.sendRedirect(request.getContextPath() + "/login?logout=true"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 returnid
claim (which is an integer) , some returnsub
claim (which is a 128-bit UUID). But everyone always support and return theemail
claim.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's true, unfortunately
sub
the newer version of the unique-id claim. And not all providers support it. Some still use the oldid
claim