Unable to use JWT with c#

Hello, i havethis exemple :

And am trying to make it work with my WPF.
Here is my code : The key is the real key, (read only actions) so you can try this.
i got 401 error, i cannot be autentified. I tryed a lots of think, and am now lost and without more ideas, please can someone help me?

 public class JWT1
    {
        private const string tokenId = "419506";
        private const string key = "/V2qzwXZ6+inAQ/ygqTUMq5yEYOZBOSVzOEK6wjGJuh/YpaP/y7a1ge8s03ycEWVcAgaQt1ghmNRg5Izk3nHNw==";

        public static void Test()
        {
            GetRequest("/orders?product_id=1");
        }

        private static void GetRequest(string getString)
        {
            string encoded = Encode(getString);
            Debug.WriteLine("token : \n" + encoded);
            WebRequest request = WebRequest.Create("https://api.quoine.com"+ getString);
            request.Method = "GET";
            request.Timeout = 12000;
            request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired;
            request.ContentType = "application/json";
            request.Headers.Add("X-Quoine-API-Version", "2");
            request.Headers.Add("X-Quoine-Auth", encoded);
            WebResponse response = null;
            
            try
            {
                response = request.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Stream stream = response.GetResponseStream();
                StreamReader reader = new StreamReader(stream);
                Debug.WriteLine("encoded : " + encoded);
                //Debug.WriteLine("StatuDesc : " + response.StatusDescription);
                //Debug.WriteLine("Statucode : " + response.StatusCode);
                //Debug.WriteLine("Charac : " + response.CharacterSet);
                Debug.WriteLine("Stream : " + reader.ReadToEnd());
                response.Close();
            }

        }
        private static string Encode(string request)
        {
            // Create Security key  using private key above:
            // not that latest version of JWT using Microsoft namespace instead of System
            //SymmetricSecurityKey securityKey = new SymmetricSecurityKey(Convert.FromBase64String(key));
            SymmetricSecurityKey securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
            // Also note that securityKey length should be >256b
            // so you have to make sure that your private key has a proper length
            SigningCredentials credentials = new SigningCredentials
                              (securityKey, SecurityAlgorithms.HmacSha256);

            //  Finally create a Token
            JwtHeader header = new JwtHeader(credentials);

            //Some PayLoad that contain information about the  customer
            JwtPayload payload = new JwtPayload
           {
               { "path ", request},
               { "nonce", DateTime.Now.Ticks},
                {"token_id",tokenId }
           };
            //IdentityModelEventSource.ShowPII = true;
            //Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]', SecurityKey: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'
            JwtSecurityToken secToken = new JwtSecurityToken(header, payload);
            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();

            // Token to String so you can use it in your client
            return handler.WriteToken(secToken);


        }
    }

Hey @ElFab

As it has been more than a few months since this topic was opened and there has been no reply or further information provided from the community as to the existence of the issue we would like to check if you are still facing the described challenge?

We are more than happy to assist in any way! If the issue is still out there please let us know so we can create a new thread for better visibility, otherwise we’ll close this one in week’s time.

Thank you!

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.