-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support self-signed long-lived session tokens
Closes #18
- Loading branch information
1 parent
4376e9f
commit abe2d8b
Showing
7 changed files
with
176 additions
and
14 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
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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/faforever/icebreaker/security/CustomTenantResolver.kt
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,36 @@ | ||
package com.faforever.icebreaker.security | ||
|
||
import com.faforever.icebreaker.config.FafProperties | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import io.quarkus.oidc.TenantResolver | ||
import io.vertx.core.http.HttpHeaders.AUTHORIZATION | ||
import io.vertx.ext.web.RoutingContext | ||
import jakarta.enterprise.context.ApplicationScoped | ||
|
||
/** | ||
* This application supports 2 JWT providers: | ||
* | ||
* * "Official" FAF access token from Ory Hydra (hydra.faforever.com) | ||
* * Self-signed JWTs inside this service that are used for extended session token. | ||
* | ||
* This tenant resolver selects the right provider based on the issuer of the JWT. | ||
*/ | ||
@ApplicationScoped | ||
class CustomTenantResolver( | ||
private val fafProperties: FafProperties, | ||
private val objectMapper: ObjectMapper, | ||
) : TenantResolver { | ||
|
||
override fun resolve(context: RoutingContext): String? = | ||
context.request().getHeader(AUTHORIZATION) | ||
?.takeIf { it.startsWith("Bearer ") } | ||
?.let { | ||
val rawToken = it.substring(7) | ||
val body = java.util.Base64.getDecoder().decode(rawToken.split(".")[1]) | ||
val json = objectMapper.readTree(body) | ||
|
||
json["iss"]?.textValue() | ||
} | ||
?.takeIf { it == fafProperties.selfUrl() } | ||
?.let { "self-tenant" } | ||
} |
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
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