You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting a null reference error when trying to decode a jwt token without adding a key paramater. In the example code it is shown. I am Using package JWT v 10.1.1
Code generating the token:
publicstringCreateJWT(Typeclaims){varpayload=newDictionary<string,object>{
...{"exp", DateTimeOffset.UtcNow.Add(TokenExpiry).ToUnixTimeSeconds()}};IJwtAlgorithmalgorithm=new HMACSHA256Algorithm();IJsonSerializerserializer=new JsonNetSerializer();IBase64UrlEncoderurlEncoder=new JwtBase64UrlEncoder();IJwtEncoderencoder=new JwtEncoder(algorithm, serializer, urlEncoder);stringkey=string.Empty;// cant encode without a keyvartoken= encoder.Encode(payload, key);returntoken;}
System.NullReferenceException: Object reference not set to an instance of an object.
at JWT.JwtDecoder.<>c.<AllKeysHaveValues>b__20_0(Byte[] key)
at System.Array.TrueForAll[T](T[] array, Predicate`1 match)
at JWT.JwtDecoder.AllKeysHaveValues(Byte[][] keys)
at JWT.JwtDecoder.ValidSymmetricAlgorithm(Byte[][] keys, String decodedPayload, IJwtAlgorithm algorithm, Byte[] bytesToSign, Byte[] decodedSignature)
at JWT.JwtDecoder.Validate(JwtParts jwt, Byte[][] keys)
at JWT.JwtDecoder.Decode(JwtParts jwt, Byte[][] keys, Boolean verify)
at JWT.JwtDecoder.Decode(JwtParts jwt, Byte[] key, Boolean verify)
at JWT.JwtDecoder.Decode(JwtParts jwt, Boolean verify)
at JWT.JwtDecoder.DecodeToObject(Type type, JwtParts jwt, Boolean verify)
at JWT.JwtDecoderExtensions.DecodeToObject[T](IJwtDecoder decoder, JwtParts jwt, Boolean verify)
at JWT.JwtDecoderExtensions.DecodeToObject[T](IJwtDecoder decoder, String token)
at POC.Tests.Tests.<>c__DisplayClass2_0.<TestExpiredToken>b__0() in C:\Projects\.net 8 Rest POC\Tests\TokenManagementTests.cs:line 98
at NUnit.Framework.Assert.Throws(IResolveConstraint expression, TestDelegate code, String message, Object[] args)>
I am getting a null reference error when trying to decode a jwt token without adding a key paramater. In the example code it is shown. I am Using package JWT v 10.1.1
Code generating the token:
Test code:
The text was updated successfully, but these errors were encountered: