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
The decoding process in JWT is generally performed on the token sent from the client side. For this token, invalid values such as missing strings need to be considered. Generally, the TryXxx method doesn't throw any exceptions and returns the boolean value of success/failure. However, TryDecode method throws an exception when an invalid value is passed.
Reproduction Code
usingLitJWT;usingLitJWT.Algorithms;usingUtf8Json;voidMain(){varalgo=newHS256Algorithm(HS256Algorithm.GenerateRandomRecommendedKey());varencoder=newJwtEncoder(algo);vardecoder=newJwtDecoder(encoder.SignAlgorithm);varinput=newPerson{Name="xin9le",Age=36};varexpiry=TimeSpan.FromSeconds(10);varjwt=encoder.Encode(input,expiry,(x,w)=>w.Write(JsonSerializer.SerializeUnsafe(x)));jwt.Dump("JWT");varinvalidJwt=jwt.AsSpan(0,10);varresult=decoder.TryDecode(invalidJwt, x =>JsonSerializer.Deserialize<Person>(x.ToArray()),outvaroutput);result.Dump("Result");output.Dump("Output");}publicclassPerson{publicstringName{get;init;}publicintAge{get;init;}}
Expected behavior
No exception occurs
Should return enum value like DecodeResult.InvalidFormat
The text was updated successfully, but these errors were encountered:
Summary
The decoding process in JWT is generally performed on the token sent from the client side. For this token, invalid values such as missing strings need to be considered. Generally, the
TryXxx
method doesn't throw any exceptions and returns the boolean value of success/failure. However,TryDecode
method throws an exception when an invalid value is passed.Reproduction Code
Expected behavior
DecodeResult.InvalidFormat
The text was updated successfully, but these errors were encountered: