working on token endpoint

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-24 00:57:15 +02:00
parent fe14e81304
commit 09e5a52c53
11 changed files with 153 additions and 135 deletions

View File

@@ -10,12 +10,12 @@ import java.util.UUID;
public record Client(String id, String name, String secret, Set<String> redirectUris) {
private static System.Logger LOG = System.getLogger(Client.class.getSimpleName());
public Map<String, Object> map() {
return Map.of(CLIENT_ID, id, NAME, name, SECRET, secret, REDIRECT_URIS, redirectUris);
public Map<String, Object> map() {
return Map.of(CLIENT_ID, id, NAME, name, SECRET, secret, REDIRECT_URIS, redirectUris);
}
public String generateCode() {
LOG.log(WARNING,"{0}.generateCode() not implemented!", getClass().getSimpleName());
LOG.log(WARNING, "{0}.generateCode() not implemented!", getClass().getSimpleName());
return UUID.randomUUID().toString();
}
}

View File

@@ -6,9 +6,11 @@ public class Constants {
public static final String CLIENT_ID = "client_id";
public static final String CODE = "code";
public static final String CONFIRMED = "confirmed";
public static final String GRANT_TYPE = "grant_type";
public static final String NAME = "name";
public static final String REDIRECT_URI = "redirect_uri";
public static final String REDIRECT_URIS = "redirect_uris";
public static final String SECRET = "secret";
public static final String STATE = "state";
public static final String ATUH_CODE = "authorization_code";
}

View File

@@ -18,12 +18,14 @@ import java.util.stream.Stream;
import org.json.JSONObject;
public abstract class PathHandler implements HttpHandler {
public System.Logger LOG = System.getLogger(getClass().getSimpleName());
public static final String CONTENT_TYPE = "Content-Type";
public static final String DELETE = "DELETE";
public static final String GET = "GET";
public static final String JSON = "application/json";
public static final String POST = "POST";
public static final String CONTENT_TYPE = "Content-Type";
public static final String DELETE = "DELETE";
private static final String FORWARDED_HOST = "x-forwarded-host";
public static final String GET = "GET";
public static final String HOST = "host";
public static final String JSON = "application/json";
public static System.Logger LOG = System.getLogger(PathHandler.class.getSimpleName());
public static final String POST = "POST";
private String[] paths;
@@ -96,7 +98,10 @@ public abstract class PathHandler implements HttpHandler {
}
public static String hostname(HttpExchange ex) {
return "http://%s".formatted(ex.getRequestHeaders().getFirst("Host"));
var headers = ex.getRequestHeaders();
var host = headers.getFirst(FORWARDED_HOST);
if (host == null) host = headers.getFirst(HOST);
return host == null ? null : "https://"+host;
}
public static JSONObject json(HttpExchange ex) throws IOException {
@@ -118,6 +123,7 @@ public abstract class PathHandler implements HttpHandler {
}
public static boolean sendContent(HttpExchange ex, int status, byte[] bytes) throws IOException {
LOG.log(DEBUG, "sending {0} response…", status);
ex.sendResponseHeaders(status, bytes.length);
ex.getResponseBody().write(bytes);
return true;