Skip to content

Commit 38ac0e1

Browse files
fixed access token expiration check
1 parent 18c1355 commit 38ac0e1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/kotlin/com/viaversion/aas/web/WebLogin.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,22 @@ class WebLogin : WebState {
155155
private suspend fun handleSaveAccessToken(webClient: WebClient, obj: JsonObject) {
156156
val accessToken = obj["mc_access_token"].asString
157157
val decodedToken = JWT.decode(accessToken)
158-
assert(decodedToken.expiresAtAsInstant <= Instant.now())
159-
assert(decodedToken.notBeforeAsInstant >= Instant.now())
158+
val now = Instant.now()
159+
if (now > decodedToken.expiresAtAsInstant) {
160+
throw IllegalArgumentException("mc access token has expired")
161+
}
162+
if (now < decodedToken.notBeforeAsInstant) {
163+
throw IllegalArgumentException("mc access token notBefore is in the future")
164+
}
160165
val expectedId = UUID.fromString(decodedToken.getClaim("profiles").asMap()["mc"].toString())
161166

162167
val profile = AspirinServer.httpClient.get("https://api.minecraftservices.com/minecraft/profile") {
163168
header("Authorization", "Bearer $accessToken")
164169
}.body<JsonObject>()
165170
val uuid = parseUndashedId(profile["id"].asString)
166-
assert(uuid == expectedId)
171+
if (uuid != expectedId) {
172+
throw IllegalStateException("expected $expectedId == $uuid")
173+
}
167174

168175
webClient.server.addAccessToken(uuid, accessToken)
169176
webLogger.info("Received token: {} {}", webClient.id, uuid)

0 commit comments

Comments
 (0)