Created
September 25, 2018 19:23
-
-
Save rony4d/5596ef9ac8e88502ee997e046b0f567b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Security.Cryptography; | |
| using System.Security.Cryptography.X509Certificates; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.IO; | |
| using Jose; | |
| using Microsoft.AspNetCore.Mvc; | |
| using Org.BouncyCastle.Crypto; | |
| using Org.BouncyCastle.OpenSsl; | |
| using Org.BouncyCastle.Crypto.Encodings; | |
| using Org.BouncyCastle.Crypto.Engines; | |
| using Security.Cryptography; | |
| namespace JWTTestApp.Controllers | |
| { | |
| [Route("api/[controller]")] | |
| [ApiController] | |
| public class ValuesController : ControllerBase | |
| { | |
| // GET api/values | |
| [HttpGet] | |
| public string Get() | |
| { | |
| var payload = new Dictionary<string, object>(){ | |
| { "iss", "xxxx"}, | |
| { "exp", 1537918404260 }, | |
| { "iat", 1537896804261}, | |
| { "sub", "earn"}, | |
| { "offer", new Dictionary<string, object>(){ {"id", "5baa7164c37bac001552b307" }, { "amount", 200 } } }, | |
| { "recipient", new Dictionary<string, object>(){ { "user_id", "9f384ad8-1f7a-4554-9806-xxxxxxxx" }, { "title", "demo" }, { "description", "demo" } } } | |
| }; | |
| var header = new Dictionary<string, object>() { { "typ","JWT"}, { "kid", "es256_9B6B64E0-64B4-46BB-97AC-xxxxxxxx" } }; | |
| var privateKey = new X509Certificate2("pkeys/server.p12","ugo").GetECDsaPrivateKey(); | |
| string token = Jose.JWT.Encode(payload, privateKey, JwsAlgorithm.ES256, header); | |
| return token; | |
| } | |
| // GET api/values/5 | |
| [HttpGet("{id}")] | |
| public string Get(int id) | |
| { | |
| return "value"; | |
| } | |
| // POST api/values | |
| [HttpPost] | |
| public void Post([FromBody] string value) | |
| { | |
| } | |
| // PUT api/values/5 | |
| [HttpPut("{id}")] | |
| public void Put(int id, [FromBody] string value) | |
| { | |
| } | |
| // DELETE api/values/5 | |
| [HttpDelete("{id}")] | |
| public void Delete(int id) | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment