Shamrock: fix #238

This commit is contained in:
白池 2024-02-18 07:45:48 +08:00
parent 8e6c167987
commit 2c8b57a7dc
2 changed files with 6 additions and 4 deletions

View File

@ -60,8 +60,10 @@ internal class WebSocketService(
}
override fun onOpen(conn: WebSocket, handshake: ClientHandshake) {
val token = ShamrockConfig.getActiveWebSocketConfig()?.token ?: ShamrockConfig.getToken()
if (token.isNotBlank()) {
val token = ShamrockConfig.getActiveWebSocketConfig()?.tokens
?: ShamrockConfig.getActiveWebSocketConfig()?.token?.split(",", "|", "")
?: listOf(ShamrockConfig.getToken())
if (token.isNotEmpty()) {
var accessToken = handshake.getFieldValue("access_token")
.ifNullOrEmpty(handshake.getFieldValue("ticket"))
.ifNullOrEmpty(handshake.getFieldValue("Authorization"))
@ -69,8 +71,7 @@ internal class WebSocketService(
if (accessToken.startsWith("Bearer ", ignoreCase = true)) {
accessToken = accessToken.substring(7)
}
val tokenList = token.split(",", "|", "")
if (!tokenList.contains(accessToken)) {
if (!token.contains(accessToken)) {
conn.close()
LogCenter.log({ "WSServer连接错误(${conn.remoteSocketAddress.address.hostAddress}:${conn.remoteSocketAddress.port}) 没有提供正确的token, $accessToken" }, Level.ERROR)
return

View File

@ -18,6 +18,7 @@ data class ConnectionConfig(
@SerialName("address") val address: String? = null,
@SerialName("port") var port: Int? = null,
@SerialName("token") val token: String? = null,
@SerialName("tokens") val tokens: List<String>? = null,
@SerialName("heartbeat_interval") var heartbeatInterval: Long? = null,
)