{"id":18778100,"url":"https://github.com/ststeiger/jwt_net20","last_synced_at":"2025-04-13T10:32:58.482Z","repository":{"id":37925463,"uuid":"68789121","full_name":"ststeiger/Jwt_Net20","owner":"ststeiger","description":"JWT  (JSON Web Tokens) for .NET 2.0 and .NET Core - www.iana.org/assignments/jose/jose.xhtml","archived":false,"fork":false,"pushed_at":"2022-06-22T17:50:57.000Z","size":9638,"stargazers_count":8,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T02:39:01.598Z","etag":null,"topics":["authentication","authentication-microservice","csharp","iana-jose","jwt","netframework2","vbnet"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ststeiger.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-09-21T06:56:09.000Z","updated_at":"2024-08-01T22:34:28.000Z","dependencies_parsed_at":"2022-08-25T22:20:40.828Z","dependency_job_id":null,"html_url":"https://github.com/ststeiger/Jwt_Net20","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/ststeiger%2FJwt_Net20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ststeiger%2FJwt_Net20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ststeiger%2FJwt_Net20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ststeiger%2FJwt_Net20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ststeiger","download_url":"https://codeload.github.com/ststeiger/Jwt_Net20/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248699172,"owners_count":21147596,"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":["authentication","authentication-microservice","csharp","iana-jose","jwt","netframework2","vbnet"],"created_at":"2024-11-07T20:15:03.122Z","updated_at":"2025-04-13T10:32:56.957Z","avatar_url":"https://github.com/ststeiger.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Web Token (JWT) Implementation for .NET\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%2Fststeiger%2Fjwt_net20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fststeiger%2Fjwt_net20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fststeiger%2Fjwt_net20/lists"}