From 8678c0dcf2af0c0d13f7e0ef4417a4fef88bd564 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Fri, 12 Jan 2024 20:53:47 -0700 Subject: [PATCH] auth: Always check token.exp when launch game (#2642) * auth: Always check token.exp when launch game fix #2048 * Remove wrong notAfter check --- .../hmcl/auth/microsoft/MicrosoftAccount.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftAccount.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftAccount.java index d9eb451a7..810f56a91 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftAccount.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftAccount.java @@ -84,20 +84,16 @@ public class MicrosoftAccount extends OAuthAccount { @Override public AuthInfo logIn() throws AuthenticationException { - if (!authenticated) { - if (service.validate(session.getNotAfter(), session.getTokenType(), session.getAccessToken())) { - authenticated = true; - } else { - MicrosoftSession acquiredSession = service.refresh(session); - if (!Objects.equals(acquiredSession.getProfile().getId(), session.getProfile().getId())) { - throw new ServerResponseMalformedException("Selected profile changed"); - } - - session = acquiredSession; - - authenticated = true; - invalidate(); + if (!authenticated || !service.validate(session.getNotAfter(), session.getTokenType(), session.getAccessToken())) { + MicrosoftSession acquiredSession = service.refresh(session); + if (!Objects.equals(acquiredSession.getProfile().getId(), session.getProfile().getId())) { + throw new ServerResponseMalformedException("Selected profile changed"); } + + session = acquiredSession; + + authenticated = true; + invalidate(); } return session.toAuthInfo();