Skip to content

feat: added logout url to logout method #102

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kinde-core/src/main/java/com/kinde/KindeClientSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface KindeClientSession {
AuthorizationUrl register();

AuthorizationUrl logout() throws Exception;

AuthorizationUrl logout(String logoutRedirectUri) throws Exception;

UserInfo retrieveUserInfo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.nimbusds.openid.connect.sdk.UserInfoResponse;
import com.nimbusds.openid.connect.sdk.token.OIDCTokens;
import lombok.SneakyThrows;
import com.kinde.KindeClientSession;
import com.kinde.authorization.AuthorizationUrl;

import java.net.URI;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@
return authorizationUrlWithParameters(parameters);
}

@Override
public AuthorizationUrl logout() throws Exception {
if (this.kindeConfig.logoutRedirectUri() == null || this.kindeConfig.logoutRedirectUri().isEmpty()) {
throw new Exception("Logout url is not provided");
return logout(this.kindeConfig.logoutRedirectUri());
}

@Override
public AuthorizationUrl logout(String logoutRedirectUri) throws Exception {
if (logoutRedirectUri == null || logoutRedirectUri.isEmpty()) {
throw new Exception("Logout redirect URI is not provided");

Check warning on line 170 in kinde-core/src/main/java/com/kinde/session/KindeClientSessionImpl.java

View check run for this annotation

Codecov / codecov/patch

kinde-core/src/main/java/com/kinde/session/KindeClientSessionImpl.java#L170

Added line #L170 was not covered by tests
}
return new AuthorizationUrl(new URL(String.format("%s?redirect=%s",this.oidcMetaData.getOpMetadata().getEndSessionEndpointURI().toURL(),
this.kindeConfig.logoutRedirectUri())),null);
logoutRedirectUri)),null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
AuthorizationUrl authorizationUrl = KindeSingleton
String logoutRedirectUri = req.getParameter("redirect_uri");

Check warning on line 30 in kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java

View check run for this annotation

Codecov / codecov/patch

kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java#L30

Added line #L30 was not covered by tests
AuthorizationUrl authorizationUrl;

KindeClientSession clientSession = KindeSingleton
.getInstance()
.getKindeClientBuilder()
.build()
.clientSession().logout();
.clientSession();

Check warning on line 37 in kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java

View check run for this annotation

Codecov / codecov/patch

kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java#L37

Added line #L37 was not covered by tests

if (logoutRedirectUri != null && !logoutRedirectUri.isEmpty()) {
authorizationUrl = clientSession.logout(logoutRedirectUri);

Check warning on line 40 in kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java

View check run for this annotation

Codecov / codecov/patch

kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java#L40

Added line #L40 was not covered by tests
} else {
authorizationUrl = clientSession.logout();

Check warning on line 42 in kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java

View check run for this annotation

Codecov / codecov/patch

kinde-j2ee/src/main/java/com/kinde/servlet/KindeLogoutServlet.java#L42

Added line #L42 was not covered by tests
}

HttpSession session = req.getSession(false);
if (session != null) {
session.removeAttribute(ACCESS_TOKEN);
Expand Down