6

I'm trying to implement authentication by use of JSON Web Tokens (JWT) in Unity 3D. I searched a lot in google and GitHub and found nothing useful. There is a .NET library in GitHub but i don't know how to use it.

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet

I'm new to unity and any help with this would be great.

9

3 Answers 3

3

Here is one way to decode a JSON web token with C# in Unity

var parts = token.Split('.');
if (parts.Length > 2)
{
    var decode = parts[1];
    var padLength = 4 - decode.Length % 4;
    if (padLength < 4)
    {
        decode += new string('=', padLength);
    }
    var bytes = System.Convert.FromBase64String(decode);
    var userInfo = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
}
1
  • You should have at least stated that your code is a security vulnerability. You left the signature unverified.
    – ZARKONES
    Mar 9, 2022 at 20:43
2

Sorry for delay,

I found this: Jwt.Net

It actually supports the proper .NET version you need for unity3d which is 3.5 Just try to find DLLs, then put them in your unity project.

Hope it helps.

0

It won't work with unity because that is for .Net 3.5. (https://github.com/jwt-dotnet/jwt)

Unity is still using .Net 2.0 @ version 5.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.