简体   繁体   中英

How to use JSON Web Token (JWT) in Unity 3d?

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.

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.

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);
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM