{"id":13598247,"url":"https://github.com/monry/JWT-for-Unity","last_synced_at":"2025-04-10T06:31:32.675Z","repository":{"id":145560837,"uuid":"51695589","full_name":"monry/JWT-for-Unity","owner":"monry","description":"JWT (JSON Web Token) implementation for .NET 3.5+ (Public Domain)","archived":false,"fork":true,"pushed_at":"2016-02-14T13:37:31.000Z","size":4698,"stargazers_count":80,"open_issues_count":0,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-06T22:41:33.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"Install-Package JWT","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jwt-dotnet/jwt","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-14T13:25:05.000Z","updated_at":"2024-10-10T15:41:21.000Z","dependencies_parsed_at":"2023-06-05T10:00:41.884Z","dependency_job_id":null,"html_url":"https://github.com/monry/JWT-for-Unity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monry%2FJWT-for-Unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monry%2FJWT-for-Unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monry%2FJWT-for-Unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monry%2FJWT-for-Unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monry","download_url":"https://codeload.github.com/monry/JWT-for-Unity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248168235,"owners_count":21058793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T17:00:50.811Z","updated_at":"2025-04-10T06:31:27.655Z","avatar_url":"https://github.com/monry.png","language":"C#","funding_links":[],"categories":["C# #","Game Development"],"sub_categories":["Unity Engine: Resources"],"readme":"# JSON Web Token (JWT) Implementation for Unity (C\\#)\n\nThis library supports generating and decoding [JSON Web Tokens](http://tools.ietf.org/html/draft-jones-json-web-token-10).\n\n## Installation\nThe easiest way to install is via NuGet.  See [here](https://nuget.org/packages/JWT).  Else, you can download and compile it yourself.\n\n## Usage\n### Creating Tokens\n\n```csharp\nvar payload = new Dictionary\u003cstring, object\u003e()\n{\n    { \"claim1\", 0 },\n    { \"claim2\", \"claim2-value\" }\n};\nvar secretKey = \"GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk\";\nstring token = JWT.JsonWebToken.Encode(payload, secretKey, JWT.JwtHashAlgorithm.HS256);\nConsole.WriteLine(token);\n```\n\nOutput will be:\n    eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGFpbTEiOjAsImNsYWltMiI6ImNsYWltMi12YWx1ZSJ9.8pwBI_HtXqI3UgQHQ_rDRnSQRxFL1SR8fbQoS-5kM5s\n\n### Verifying and Decoding Tokens\n\n```csharp\nvar token = \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGFpbTEiOjAsImNsYWltMiI6ImNsYWltMi12YWx1ZSJ9.8pwBI_HtXqI3UgQHQ_rDRnSQRxFL1SR8fbQoS-5kM5s\";\nvar secretKey = \"GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk\";\ntry\n{\n    string jsonPayload = JWT.JsonWebToken.Decode(token, secretKey);\n    Console.WriteLine(jsonPayload);\n}\ncatch (JWT.SignatureVerificationException)\n{\n    Console.WriteLine(\"Invalid token!\");\n}\n```\n\nOutput will be:\n\n    {\"claim1\":0,\"claim2\":\"claim2-value\"}\n\nYou can also deserialize the JSON payload directly to a .Net object with DecodeToObject:\n\n```csharp\nvar payload = JWT.JsonWebToken.DecodeToObject(token, secretKey) as IDictionary\u003cstring, object\u003e;\nConsole.WriteLine(payload[\"claim2\"]);\n```\n\nwhich will output:\n    \n    claim2-value\n\n#### exp claim\n\nAs described in the [JWT RFC](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.4) the `exp` \"claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing.\" If an `exp` claim is present and is prior to the current time the token will fail verification. The exp (expiry) value must be specified as the number of seconds since 1/1/1970 UTC.\n\n```csharp\nvar unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);\nvar now = Math.Round((DateTime.UtcNow - unixEpoch).TotalSeconds);\nvar payload = new Dictionary\u003cstring, object\u003e()\n{\n    { \"exp\", now }\n};\nvar secretKey = \"GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk\";\nstring token = JWT.JsonWebToken.Encode(payload, secretKey, JWT.JwtHashAlgorithm.HS256);\n\nstring jsonPayload = JWT.JsonWebToken.Decode(token, secretKey); // JWT.SignatureVerificationException!\n```\n\n### Configure JSON Serialization\n\nBy default JSON Serialization is done by System.Web.Script.Serialization.JavaScriptSerializer.  To configure a different one first implement the IJsonSerializer interface.\n\n```csharp\npublic class CustomJsonSerializer : IJsonSerializer\n{\n    public string Serialize(object obj)\n    {\n        // Implement using favorite JSON Serializer\n    }\n\n    public T Deserialize\u003cT\u003e(string json)\n    {\n        // Implement using favorite JSON Serializer\n    }\n}\n```\n\nNext configure this serializer as the JsonSerializer.\n```cs\nJsonWebToken.JsonSerializer = new CustomJsonSerializer();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonry%2FJWT-for-Unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonry%2FJWT-for-Unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonry%2FJWT-for-Unity/lists"}