{"id":22353029,"url":"https://github.com/esskar/sodium.identitymodel.tokens","last_synced_at":"2025-08-22T10:12:06.248Z","repository":{"id":136981479,"uuid":"342986401","full_name":"esskar/Sodium.IdentityModel.Tokens","owner":"esskar","description":"Includes types that provide support for Sodium/Nacl SecurityTokens, Cryptographic operations: Signing, Verifying Signatures.","archived":false,"fork":false,"pushed_at":"2021-02-28T17:48:41.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T12:49:29.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esskar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-28T00:15:27.000Z","updated_at":"2023-08-12T14:49:25.000Z","dependencies_parsed_at":"2023-04-24T14:02:25.379Z","dependency_job_id":null,"html_url":"https://github.com/esskar/Sodium.IdentityModel.Tokens","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/esskar%2FSodium.IdentityModel.Tokens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esskar%2FSodium.IdentityModel.Tokens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esskar%2FSodium.IdentityModel.Tokens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esskar%2FSodium.IdentityModel.Tokens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esskar","download_url":"https://codeload.github.com/esskar/Sodium.IdentityModel.Tokens/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245650459,"owners_count":20650105,"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-12-04T12:32:27.710Z","updated_at":"2025-03-26T12:20:32.634Z","avatar_url":"https://github.com/esskar.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sodium.IdentityModel.Tokens\n\nIncludes types that provide support for Sodium/NaCl SecurityTokens, Cryptographic operations: Signing, Verifying Signatures.\n\n## Description\n\nHelps to protect your ASP.NET core API with JSON Web Token signed using Edwards-curve \nDigital Signature Algorithm ([EdDSA][eddsa]) [curve Ed25519 digital signatures][ed25519] from the \nstate-of-the-art Sodium/NaCl [Networking and Cryptography library][nacl] by [Daniel J. Bernstein][bernstein]. \n\n## Installation\n\n```shell\ndotnet add package Sodium.IdentityModel.Tokens\n```\n\n## Usage\n\n### Create a key pair\n\nFirst, you need to create a private/public key pair.\n\n```csharp\nusing Sodium;\n\nvar keyPair = PublicKeyAuth.GenerateKeyPair();\n```\n\nYou can access the private key via `keyPair.PrivateKey`. Keep it protected, it will be used to sign your tokens.\nThe public key will be used to verify your signed tokens. Access it via `keyPair.PublicKey`.\n\n### Create and sign your tokens\n\nCreate a security key from the private key\n\n```csharp\nvar securityKey = SodiumSecurityKey.FromPrivateKey(privateKey);\n```\n\nCreate a signing credentials using the just created security key. \n\n```csharp\nvar credentials = new SigningCredentials(securityKey, SodiumAlgorithms.EdDsa)\n{\n    CryptoProviderFactory = new CryptoProviderFactory\n    {\n        CustomCryptoProvider = new SodiumCryptoProvider()\n    }\n};\n```\n\nBuild your token based on the current identity and write it with a `JwtSecurityTokenHandler`\n\n```powershell\nvar tokenHandler = new JwtSecurityTokenHandler();\n\nvar claims = new List\u003cClaim\u003e\n{\n    new Claim(ClaimTypes.Name, identity.Name)\n};\n\nvar securityToken = new JwtSecurityToken(\n    \"me\",   \n    \"you\",\n    claims,    \n    expires: DateTime.UtcNow.AddDays(1),    \n    signingCredentials: credentials);\n\n\nvar token = tokenHandler.WriteToken(securityToken);\n```\n\n[eddsa]: https://en.wikipedia.org/wiki/EdDSA\n[ed25519]: http://ed25519.cr.yp.to/\n[nacl]: http://nacl.cr.yp.to/\n[bernstein]: https://en.wikipedia.org/wiki/Daniel_J._Bernstein\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesskar%2Fsodium.identitymodel.tokens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesskar%2Fsodium.identitymodel.tokens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesskar%2Fsodium.identitymodel.tokens/lists"}