From 8c065320c2c600045bce84ad71b130f51119c7f4 Mon Sep 17 00:00:00 2001 From: Justin Slauson Date: Tue, 1 Mar 2016 19:40:54 -0700 Subject: [PATCH] validates token successully --- MinecraftClient/Protocol/ProtocolHandler.cs | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 6377cd49..d02f557e 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -211,6 +211,39 @@ namespace MinecraftClient.Protocol } } + public enum ValidationResult { Validated, RefreshRequired, Error }; + + /// + /// Validates whether accessToken must be refreshed + /// + /// Will contain the cached access token previously returned by Minecraft.net + /// Returns the status of the token (Valid, Invalid, etc.) + /// + public static ValidationResult GetTokenValidation(string accesstoken) + { + try + { + string result = ""; + string json_request = "{\"accessToken\": \"" + jsonEncode(accesstoken) + "\" }"; + int code = doHTTPSPost("authserver.mojang.com", "/validate", json_request, ref result); + if (code == 204) + { + return ValidationResult.Validated; + } + else if (code == 403) + { + return ValidationResult.RefreshRequired; + } + else + { + return ValidationResult.Error; + } + } + catch + { + return ValidationResult.Error; + } + } /// /// Check session using Mojang's Yggdrasil authentication scheme. Allows to join an online-mode server ///