Code Monkey home page Code Monkey logo

jwt's People

Contributors

abatishchev avatar abrasat avatar binki avatar bjnoelucanr avatar dependabot[bot] avatar dstj avatar fishdawg avatar flerka avatar furgas avatar glennawatson avatar hartmark avatar johnsheehan avatar latchkostov avatar lechu445 avatar mderriey avatar mikelehen avatar mmfazrin-phcc-gov avatar moritzgloeckl avatar nbarbettini avatar paule96 avatar pbouillon avatar purekrome avatar quintushr avatar randy-armstrong avatar simon-pearson avatar simonedamico avatar skimbrel avatar thughes avatar zemien avatar zexuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jwt's Issues

How to use this library with Asp.net Web Api Core?

I have been successfully using this library with the previous Web Api with absolutely no problems. Now, I'm starting a brand new project with Asp.net Core Web Api, however I can still generate tokens but I don't know how to hook this up with the Controller's Authorize Attribute. Can someone please provide me a sample or something?

Trying to verify token does not work

I'm trying to verify a token sent to me by Google, but I can't. I've tried using both my clientID and my secret to verify the token. Both times it fails.

Is same Secret Key matter?

I'm sorry but this is more of question rather than an issue, since I can not find any appropriate place where to ask question.

Assuming that I have a secret key "top secret" and I used this to encode same data multiple times, will jwt always generate unique token?

Will jwt always generate unique token no matter if same secret key use to encode different data?

exp validation should parse to double, not int

JwtValidator.cs: Validate(...) converts the exp claim into an integer:
expInt = Convert.ToInt32(expObj);

However this fails if I attempt to set an expiry past 19 January 2038, the Year 2038 problem.

The definition of seconds since the epoch does not enforce that the result is an integer, merely that the "tm_sec, tm_min, tm_hour, tm_yday, and tm_year" components that are in the expression "are all integer types".

Hence I think all epoch date conversions should be parsed to double, which will support dates beyond DateTime.MaxValue.

Decode should let you specify an algorithm to use.

If for some reason I decide an algorithm is no longer safe. I should be able to stop treating tokens signed using that algorithm as "verified". if i understand the current code, if it is in the header and in the list of possible algorithms, it will be used. you might say it doesn't matter, as cracking the key will be super hard with no sample to work with (as they are all encoded using the algorithm I am using) but It is one more layer of protection, with no downsides.

suggestion:
public static string Decode(string token, byte[] key, JwtHashAlgorithm = null)

no need for "bool verify = true" for this overload.

Transfer project's ownership to the community

Hi @mikelehen,
It seems you've abandoned this project. It's great, and I'm sorry to see it stalled!
What do you think if the community would pick it up? To few maintainers such as myself. We could review the pull requests, answer the questions, etc.

Readme/Docs don't match NuGet package

NOTE:
If your reading this because your NuGet install of JWT doesn't work, the solution is at the bottom :-)

Original Question Follows Here

Trying to use the library, looking at the samples in readme.md, quite impressed at how simple lib is to use.

Great, so I install NuGet package (1.3.4) according to my nuget, but when writing code, none of the interfaces in the samples are found.

Looked in the object explorer in VS15 and all i see is this:

image

Going into each of the classes etc I don't see any of the interfaces in the sample code anywhere:

image

Please advise, do I need a different version, or is their an issue here?

Cheers
Shawty

Dependency on System.Web.Extensions

It would be great to replace the dependency on System.Web.Extensions (which is only used for Json serialization) with NewtonSoft - that way we can use this library in Xamarin projects (which Newtonsoft.Json supports, but Extensions doesn't).

How to handle secrets?

In the examples there is a secret key like:
var secret = "GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk";

Where does this key normally come from? Should we extract it i.e. from certificates?
I think it isn't something what should been hard code in our programs, am i right?

Thanx for your feedback!

Best regards
Thomas

Moving to an organization

I'm going to move this project to it's own organization. Existing owners will be added. Github should handle the redirects fine.

Base64UrlDecode throws System.Exception instead of a custom typed exception

While testing my authorization code with various forms of tokens that have been tampered with, I've noticed JsonWebToken.DecodeToObject throws a System.Exception when given an invalid token string. I've tracked it down to JsonWebToken.Base64UrlDecode. Throwing (and catching) an exception of the base Exception type is generally bad practice and I'd prefer catching a more specific exception (like ArgumentException, or the already existing SignatureVerificationException).

I haven't noticed Exception being thrown anywhere else in the class, either, so I believe this was not intentional. I've only noticed a block of code trying to catch a base Exception during a Convert.ToInt32 call. That could be altered to catch the specific exceptions the method can throw, perhaps in a similar way as here: http://stackoverflow.com/questions/136035/catch-multiple-exceptions-at-once

Verifying JWT Signature

Hi,
Am new to JWT thing. Ican able to successfully generate JWT for my app. But don't know how to verify the signature of JWT. Can anyone help me regarding this. How to verify the signature?

.NET Standard

Will you be making this compliant with .NET Standard?

Switch from VS UT Framework to xUnit?

I didn't find what's new in VS 2015 for its Unit Testing Framework (aka MSTest) but in my opinion xUnit is more flexible and dynamically developing framework.

Particularly, it supports parametrized tests of various kinds (called PropertyData in v1 and MemberData in v2).

What do you think about such switch?

Strong named assembly

Hi,

Is (or could there be) a strong named version?

I'm getting this error:
Could not load file or assembly 'JWT, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

How to decode extra header

Hi,

i'd like to decode the extra headers i added to the token,
but there seems to be no option for it?

Regards

Dedicated Verify() method

Feature request ! : Would it be useful to add a public method Verify(object Token, string Key). I want to process tokens from multiple sources. I need to decode them to recover the issuer so I know which key to use for verification. A Verify() method would save me calling Decode() twice.

RSA256 support?

I'm trying to validate a token from Google Plus. I get an error that says RSA256 is not supported. I can see the algorithm in the source code. Is there any way to get this going?

Enable CI/CD

It should be pretty easy to use travis-ci or AppVeyor to build this repo when code is checked in. Additionally, the CI script could produce the nupkg file automatically and push it somewhere like MyGet.

I've set this up before, so I'm happy to assist if you want to do this.

1.3.5-beta nupkg has no DLL

Installing the 1.3.5-beta nupkg via VS 2015 NuGet does not extract a DLL into the lib directory. 1.3.4 of course works correctly.

RFC: Ideas for v. 2.0

  • Go away from static API in favor of instance-based API with a number of separate classes:
    • JwtEncoder : IJwtEncoder
    • JwtDecoder : IJwtDecoder
    • JwtValidator : IJwtValidator
  • Mark static API [Obsolete]
  • Make static API a wrapper on top of instance-based API
  • Remove static API in the future versions (such as 2.1 or 3.0)

Split NuGet package into few child packages to ease dependencies

The idea is to extract few child packages:

  • JwtNet.Json.NewtonSoft for JsonNet based implementation of Json (de)serialization
  • JwtNet.Json.ServiceStack for ServiceStack.Text based implementations
  • JwtNet.Cryptography.RS256 for System.Security.Cryptography based implementation of RS256Algorithm

Is this library thread safe?

Hi folks,

For every Request that arrives, we attempt to decode the string token using your DecodeToObject<T> method. Great! Works fine ๐Ÿ˜„

Now, for every Request I noticed the code does the following (taken from your documentation):

var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGFpbTEiOjAsImNsYWltMiI6ImNsYWltMi12YWx1ZSJ9.8pwBI_HtXqI3UgQHQ_rDRnSQRxFL1SR8fbQoS-5kM5s";
var secret = "GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk";
try
{
    IJsonSerializer serializer = new JsonNetSerializer();
    IDateTimeProvider provider = new UtcDateTimeProvider();
    IJwtValidator validator = new JwtValidator(serializer, provider);
    IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
    IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
    
    var json = decoder.Decode(token, secret, verify: true);
    Console.WriteLine(json);
}
...
  • Create a serializer.
  • Now, create a TimeProvider.
  • ... etc..

Basically, each request keeps creating the same objects again and again.

So - why can't these be static ?

  • Create them all once.
  • _decoder.Decode(..);

e.g.

private static IJwtAlgorithm _algorithm = new HMACSHA256Algorithm();
private static IJsonSerializer _serializer = new JsonNetSerializer();
private static IDateTimeProvider _provider = new UtcDateTimeProvider();
private static IJwtValidator _validator = new JwtValidator(_serializer, _provider);
private static IBase64UrlEncoder _urlEncoder = new JwtBase64UrlEncoder();
private static IJwtEncoder _encoder = new JwtEncoder(_algorithm, _serializer, _urlEncoder);
private static IJwtDecoder _decoder = new JwtDecoder(_serializer, _validator, _urlEncoder);

<in some method>
_decoder.Decode(..);
...

So - is this possible? OK? These things thread safe?

Base64UrlEncode - Should consider trailing = character

When trying to decode segments of JWT token (first two segments) using other libraries, an exception is thrown saying invalid input or illegal base64 string. It happens since we are not considering trailing equals (=) character while encoding (in method public static string Base64UrlEncode(byte[] input)).
Please look into this and if possible then try to provide an overload so that we don't break existing clients.

Bug or question: Altering last meaningful character in base64 string doesn't change decoded outcome

after i used the function Encode() i got the token:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7IlVzZXJfTmFtZSI6ImV0YWciLCJVc2VyX0lkIjoxMDMsIlVzZXJfQWNjZXNzIjowfSwiZXhwIjoxNDgyMjA4NjM5fQ.I_aeBp9A2O2tl7VsrN0aTnHSu4Frygp25IIf6_lcixw

if i change the last char of token, e.g.:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7IlVzZXJfTmFtZSI6ImV0YWciLCJVc2VyX0lkIjoxMDMsIlVzZXJfQWNjZXNzIjowfSwiZXhwIjoxNDgyMjA4NjM5fQ.I_aeBp9A2O2tl7VsrN0aTnHSu4Frygp25IIf6_lcixx

you see i replaced last char 'w' to โ€œxโ€˜, then i use the funciton DecodeToObject(), now i still get the correct object, maybe i used a wrong method, but how did it happened?

Decode throws if payload is IDictionary<string,obj>

It seems like it should be ok for the payload to be an IDictionary but it fails to Deserialize. My work-around for the time being is simply to load my IDictionary back into a Dictionary.

IDictionary<string,obj> payload = ...
JWT.JsonWebToken.Encode(new Dictionary<string,obj>(payload), ...

version probelm

Does version 2.4.1 require version 10.0.2 of the json library?

Create a NuGet package for version 2.0.0

Hello. I am interested in working with Jwt.Net. On NuGet there is only v.1.3.4 in the stable channel, but v.2.1.1-beta in the pre-release channel. I am wondering if the 2.0.0 version is missing in the stable channel? From my perspective the version numer 2.1.1-beta tells me that 2.0.0 should be a stable release and could be added as a package to the stable channel.

Am I wrong?

Asymmetric Encryption

Could you add asymmetric encryption? That seems to be all that is missing to support JWS - JSON Web Signature.

Throw custom exceptions when decoding a token

When I use the Decode() method, a "SignatureVerificationException" exception is thrown no matter if the signature is invalid (1), the expiracy date is invalid (2) or the token has expired (3):

1.

if (decodedCrypto != decodedSignature)
{
    throw new SignatureVerificationException(string.Format("Invalid signature. Expected {0} got {1}", decodedCrypto, decodedSignature));
}

2.

try
{
   exp = Convert.ToInt32(payloadData["exp"]);
}
catch (Exception)
{
   throw new SignatureVerificationException("Claim 'exp' must be an integer.");
}

3.

if (secondsSinceEpoch >= exp)
{
   throw new SignatureVerificationException("Token has expired.");
}

cf.

jwt/JWT/JWT.cs

Line 152 in cfad0ab

throw new SignatureVerificationException(string.Format("Invalid signature. Expected {0} got {1}", decodedCrypto, decodedSignature));

Would it be possible to have a specific custom exception for each scenario? Then it would be easier and more robust to handle errors when decoding a token.

Thank you

Critical Security Fix Required: You disclose the correct signature with each SignatureVerificationException...

I just tested the result after including this library in one of our projects.
Whatever it is that you are smoking - it must be good...
You are outputting the correct signature with each SignatureVerificationException...
If I were an attacker, I would silently say "thank you" when I saw this - and wonder what drug you're on...

private static void Verify(string decodedCrypto, string decodedSignature, string payloadJson)
{
    if (decodedCrypto != decodedSignature)
    {
        // My oh my - please don't donate the correct signature to a wannabe-attacker...
        // throw new SignatureVerificationException(string.Format("Invalid signature. Expected {0} got {1}", decodedCrypto, decodedSignature));
        throw new SignatureVerificationException(string.Format("Invalid signature. Expected {0} got {1}", "SEE_LOG", decodedSignature));
    }

signature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.