mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Fix header/cookie based websocket auth (#1722)
* Fix header/cookie based websocket auth * Lint
This commit is contained in:
@@ -37,6 +37,8 @@ import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMess
|
||||
import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ServerMessages.GQL_ERROR
|
||||
import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ServerMessages.GQL_NEXT
|
||||
import suwayomi.tachidesk.graphql.server.toGraphQLContext
|
||||
import suwayomi.tachidesk.server.JavalinSetup.Attribute
|
||||
import suwayomi.tachidesk.server.JavalinSetup.getAttributeOrSet
|
||||
import suwayomi.tachidesk.server.user.UserType
|
||||
import suwayomi.tachidesk.server.user.getUserFromToken
|
||||
|
||||
@@ -152,10 +154,14 @@ class ApolloSubscriptionProtocolHandler(
|
||||
context: WsContext,
|
||||
): Flow<SubscriptionOperationMessage> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val user =
|
||||
context.getAttributeOrSet(Attribute.TachideskUser) {
|
||||
val payload = operationMessage.payload as? Map<String, Any?>
|
||||
val token = payload?.let { it[Header.AUTHORIZATION] as? String }
|
||||
getUserFromToken(token)
|
||||
}
|
||||
|
||||
saveContext(getUserFromToken(token), context)
|
||||
saveContext(user, context)
|
||||
return flowOf(acknowledgeMessage)
|
||||
}
|
||||
|
||||
|
||||
@@ -310,4 +310,11 @@ object JavalinSetup {
|
||||
fun <T : Any> Context.getAttribute(attribute: Attribute<T>): T = attribute(attribute.name)!!
|
||||
|
||||
fun <T : Any> WsContext.getAttribute(attribute: Attribute<T>): T = attribute(attribute.name)!!
|
||||
|
||||
fun <T : Any> WsContext.getAttributeOrSet(
|
||||
attribute: Attribute<T>,
|
||||
set: () -> T,
|
||||
): T =
|
||||
attribute(attribute.name)
|
||||
?: set().also { setAttribute(attribute, it) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user