Fix websocket token (#1766)

This commit is contained in:
Mitchell Syer
2025-11-06 15:26:04 -05:00
committed by GitHub
parent bb09c558b6
commit 0f95e19c76
3 changed files with 18 additions and 4 deletions

View File

@@ -251,4 +251,8 @@ tasks {
processResources {
dependsOn(":server:server-config-generate:generateSettings")
}
processTestResources {
dependsOn(":server:server-config-generate:generateSettings")
}
}

View File

@@ -155,7 +155,10 @@ class ApolloSubscriptionProtocolHandler(
): Flow<SubscriptionOperationMessage> {
@Suppress("UNCHECKED_CAST")
val user =
context.getAttributeOrSet(Attribute.TachideskUser) {
context.getAttributeOrSet(
Attribute.TachideskUser,
replaceIf = { it == UserType.Visitor },
) {
val payload = operationMessage.payload as? Map<String, Any?>
val token = payload?.let { it[Header.AUTHORIZATION] as? String }
getUserFromToken(token)

View File

@@ -319,8 +319,15 @@ object JavalinSetup {
fun <T : Any> WsContext.getAttributeOrSet(
attribute: Attribute<T>,
replaceIf: (T) -> Boolean = { false },
set: () -> T,
): T =
attribute(attribute.name)
?: set().also { setAttribute(attribute, it) }
): T {
var item: T? = attribute(attribute.name)
if (item != null && replaceIf(item)) {
item = null
}
return item ?: set().also { setAttribute(attribute, it) }
}
}