Skip to content

Commit

Permalink
fix: logout request
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 9, 2024
1 parent 3a10264 commit 1eddb69
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/io/supertokens/webserver/Webserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
import io.supertokens.webserver.api.oauth.OAuthClientListAPI;
import io.supertokens.webserver.api.oauth.OAuthGetAuthConsentRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthGetAuthLoginRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthGetAuthLogoutRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthRejectAuthConsentRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthRejectAuthLoginRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthRejectAuthLogoutRequestAPI;
import io.supertokens.webserver.api.oauth.CreateUpdateOrGetOAuthClientAPI;
import io.supertokens.webserver.api.oauth.OAuthAcceptAuthConsentRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthAcceptAuthLoginRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthAcceptAuthLogoutRequestAPI;
import io.supertokens.webserver.api.oauth.OAuthTokenAPI;
import io.supertokens.webserver.api.oauth.RemoveOAuthClientAPI;
import io.supertokens.webserver.api.passwordless.*;
Expand Down Expand Up @@ -290,6 +293,9 @@ private void setupRoutes() {
addAPI(new OAuthGetAuthLoginRequestAPI(main));
addAPI(new OAuthAcceptAuthLoginRequestAPI(main));
addAPI(new OAuthRejectAuthLoginRequestAPI(main));
addAPI(new OAuthGetAuthLogoutRequestAPI(main));
addAPI(new OAuthAcceptAuthLogoutRequestAPI(main));
addAPI(new OAuthRejectAuthLogoutRequestAPI(main));

StandardContext context = tomcatReference.getContext();
Tomcat tomcat = tomcatReference.getTomcat();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.supertokens.webserver.api.oauth;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import io.supertokens.Main;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class OAuthAcceptAuthLogoutRequestAPI extends OAuthProxyBase {

public OAuthAcceptAuthLogoutRequestAPI(Main main) {
super(main);
}

@Override
public String getPath() {
return "/recipe/oauth/auth/requests/logout/accept";
}

@Override
public ProxyProps[] getProxyProperties(HttpServletRequest req, JsonObject input) {
return new ProxyProps[] {
new ProxyProps(
"PUT", // apiMethod
"PUT_JSON", // method
"/admin/oauth2/auth/requests/logout/accept", // path
true, // proxyToAdmin
true // camelToSnakeCaseConversion
)
};
}

@Override
protected void handleResponseFromProxyPUT(HttpServletRequest req, HttpServletResponse resp, JsonObject input, int statusCode, Map<String, List<String>> headers, String rawBody, JsonElement jsonBody) throws IOException, ServletException {
JsonObject response = jsonBody.getAsJsonObject();
response.addProperty("status", "OK");
sendJsonResponse(200, response, resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.supertokens.webserver.api.oauth;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import io.supertokens.Main;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class OAuthGetAuthLogoutRequestAPI extends OAuthProxyBase {

public OAuthGetAuthLogoutRequestAPI(Main main) {
super(main);
}

@Override
public String getPath() {
return "/recipe/oauth/auth/requests/logout";
}

@Override
public ProxyProps[] getProxyProperties(HttpServletRequest req, JsonObject input) {
return new ProxyProps[] {
new ProxyProps(
"GET", // apiMethod
"GET", // method
"/admin/oauth2/auth/requests/logout", // path
true, // proxyToAdmin
true // camelToSnakeCaseConversion
)
};
}

@Override
protected void handleResponseFromProxyGET(HttpServletRequest req, HttpServletResponse resp, int statusCode,
Map<String, List<String>> headers, String rawBody, JsonElement jsonBody)
throws IOException, ServletException {

JsonObject response = jsonBody.getAsJsonObject();
response.addProperty("status", "OK");
sendJsonResponse(200, response, resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.supertokens.webserver.api.oauth;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import io.supertokens.Main;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class OAuthRejectAuthLogoutRequestAPI extends OAuthProxyBase {

public OAuthRejectAuthLogoutRequestAPI(Main main) {
super(main);
}

@Override
public String getPath() {
return "/recipe/oauth/auth/requests/logout/reject";
}

@Override
public ProxyProps[] getProxyProperties(HttpServletRequest req, JsonObject input) {
return new ProxyProps[] {
new ProxyProps(
"PUT", // apiMethod
"PUT_JSON", // method
"/admin/oauth2/auth/requests/logout/reject", // path
true, // proxyToAdmin
true // camelToSnakeCaseConversion
)
};
}

@Override
protected void handleResponseFromProxyPUT(HttpServletRequest req, HttpServletResponse resp, JsonObject input, int statusCode, Map<String, List<String>> headers, String rawBody, JsonElement jsonBody) throws IOException, ServletException {
JsonObject response = jsonBody.getAsJsonObject();
response.addProperty("status", "OK");
sendJsonResponse(200, response, resp);
}
}

0 comments on commit 1eddb69

Please sign in to comment.