简体   繁体   English

如何在 Unity 3d 中使用 JSON Web Token (JWT)?

[英]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.我正在尝试通过在 Unity 3D 中使用 JSON Web 令牌 (JWT) 来实现身份验证。 I searched a lot in google and GitHub and found nothing useful.我在 google 和 GitHub 上搜索了很多,没有发现任何有用的东西。 There is a .NET library in GitHub but i don't know how to use it. GitHub 中有一个 .NET 库,但我不知道如何使用它。

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

I'm new to unity and any help with this would be great.我是 unity 的新手,对此的任何帮助都会很棒。

Sorry for delay,不好意思推迟了,

I found this: Jwt.Net我发现了这个: 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.它实际上支持unity3d 所需的正确.NET 版本,即3.5 只需尝试查找DLL,然后将它们放入您的Unity 项目中即可。

Hope it helps.希望能帮助到你。

Here is one way to decode a JSON web token with C# in Unity这是在 Unity 中使用 C# 解码 JSON Web 令牌的一种方法

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 .它不会与 unity 一起工作,因为那是针对.Net 3.5 ( https://github.com/jwt-dotnet/jwt ) ( https://github.com/jwt-dotnet/jwt )

Unity is still using .Net 2.0 @ version 5.2 Unity 仍在使用.Net 2.0 @ version 5.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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