-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Resolve HTTP 401 error on preflight requests due to CORS (#15)
- Loading branch information
1 parent
7a4d6bd
commit bd494eb
Showing
3 changed files
with
49 additions
and
2 deletions.
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
26 changes: 26 additions & 0 deletions
26
src/main/java/dev/sultanov/keycloak/multitenancy/resource/CorsResource.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,26 @@ | ||
package dev.sultanov.keycloak.multitenancy.resource; | ||
|
||
import jakarta.ws.rs.OPTIONS; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Response; | ||
import org.keycloak.http.HttpRequest; | ||
import org.keycloak.services.resources.Cors; | ||
|
||
public class CorsResource { | ||
|
||
public static final String[] METHODS = { | ||
"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS" | ||
}; | ||
|
||
private final HttpRequest request; | ||
|
||
public CorsResource(HttpRequest request) { | ||
this.request = request; | ||
} | ||
|
||
@OPTIONS | ||
@Path("{any:.*}") | ||
public Response preflight() { | ||
return Cors.add(request, Response.ok()).auth().allowedMethods(METHODS).preflight().build(); | ||
} | ||
} |
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