mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* Microsoft Sign-in: Migrate to our own client Id - Drop support of "mcc" sign-in method - Add nuget packages for decoding JWT * Remove JWT nuget package * Remove client secret It is not needed after changing application type in Azure * Change token validation method to expiration time * Revert changes of dropping mcc sign-in method * Add email pre-fill for browser sign-in
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace MinecraftClient.Protocol
|
|
{
|
|
// Thanks to https://stackoverflow.com/questions/60404612/parse-jwt-token-to-get-the-payload-content-only-without-external-library-in-c-sh
|
|
public static class JwtPayloadDecode
|
|
{
|
|
public static string GetPayload(string token)
|
|
{
|
|
var content = token.Split('.')[1];
|
|
var jsonPayload = Encoding.UTF8.GetString(Decode(content));
|
|
return jsonPayload;
|
|
}
|
|
|
|
private static byte[] Decode(string input)
|
|
{
|
|
var output = input;
|
|
output = output.Replace('-', '+'); // 62nd char of encoding
|
|
output = output.Replace('_', '/'); // 63rd char of encoding
|
|
switch (output.Length % 4) // Pad with trailing '='s
|
|
{
|
|
case 0: break; // No pad chars in this case
|
|
case 2: output += "=="; break; // Two pad chars
|
|
case 3: output += "="; break; // One pad char
|
|
default: throw new System.ArgumentOutOfRangeException("input", "Illegal base64url string!");
|
|
}
|
|
var converted = Convert.FromBase64String(output); // Standard base64 decoder
|
|
return converted;
|
|
}
|
|
}
|
|
}
|