-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding JwtBuilder #140
Adding JwtBuilder #140
Conversation
Main changes in the validation method. This now works with the new JwtParts too Enum Name change from JwtParts to JwtPartsPointer. Today the last commit.
src/JWT/JWT.csproj
Outdated
@@ -43,5 +43,8 @@ | |||
|
|||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'"> | |||
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why both MsTest and xUnit are here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry. that was a test, to get the test runing. I remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/JWT/JWTBuilder/Builder.cs
Outdated
/// <summary> | ||
/// Build an Decode JWT for with a Fluent-API. | ||
/// </summary> | ||
public class Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call it JwtBuilder withing main JWT project since it so far doesn't add new dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reflection stuff is new. This is why I upgrade to .net standard 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you think we don't need the sub-namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd not have sub-namespaces until there are too many classes in the root or there is a strict need such as grouping/separation
src/JWT/JWTBuilder/Builder.cs
Outdated
/// Check if we have enaught information to build a new Token. | ||
/// </summary> | ||
/// <returns>Returns true if all requierd information are there to create a token.</returns> | ||
private bool canWeBuild() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanBuild()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/JWT/JWTBuilder/Builder.cs
Outdated
/// Check if we have enaught informations to decode a token. | ||
/// </summary> | ||
/// <returns>Returns ture if all requiered informations are there to create a token.</returns> | ||
private bool canWeDecode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanDecode()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/JWT/JWTBuilder/Builder.cs
Outdated
urlEncoder != null | ||
) | ||
{ | ||
if (verify && secret == null && secret.Length > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (!verify || (verify && secret == null && secret.Length > 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// All predefined Headers specified by RFC. (https://tools.ietf.org/html/rfc7519) | ||
/// Last update 31.10.2017 | ||
/// </summary> | ||
public enum HeaderNames |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HeaderName
(singular)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// </summary> | ||
/// <param name="value">A object that have the Describtion Attribut set</param> | ||
/// <returns>The string of the Describtion</returns> | ||
private static string getValueOfDescription(object value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetValueOfDescription
(CamelCase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private static string getValueOfDescription(object value) | ||
{ | ||
var info = value.GetType().GetField(value.ToString()); | ||
var attributes = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is extension method GetCustomAttribute<DescriptionAttribute>()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/JWT/JWTBuilder/Models/JWTData.cs
Outdated
/// </summary> | ||
/// <param name="Header">A Instance of a dictionary that contains the headers</param> | ||
/// <param name="PayLoad">A instance of a dictionary that contans the payload</param> | ||
public JWTData(Dictionary<string, string> Header, Dictionary<string, object> PayLoad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have class for this - JwtParts. You can reuse it once merge the projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @abatishchev I don't know if I can reuse it. I don't think this to classes represent the same stuff.
JWParts are more a think to make the work with a encoded token easier. But JWTDate is more for the decoded Token work. So you can easy add an remove data from the token befor you encode the token.
I'm not shure if I can merge this two worlds together.
Because to get a JWTData from a JWTParts you need for example a URLDecoder.
src/JWT/JWTBuilder/Models/JWTData.cs
Outdated
/// Create a new instance of JWTData and initalize Header and Payload. | ||
/// </summary> | ||
/// <returns>A Instance of <see cref"JWTData"/></returns> | ||
public JWTData() : this(Header: new Dictionary<string, string>(), PayLoad: new Dictionary<string, object>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameters should be camelCase'd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I think currently about the Extensions folder to put all the Builder-API-Methods as extension methods in separate classes, so that the builder class don't explode. What do you think about this? |
…6/jwt into issues/113_PayLoadBuilder
I have start the work to the extension methods. Please take a look at this. |
Approving so I don't block the merge later. Looking good @paule96! This adds something I've wanted in JWT.NET for a long time. 😄 I left a number of comments with small nitpicks like typos, etc. I think the library should use Cheers! |
@nbarbettini thanks a lot! You've spotted many silly errors. Made me scan the codebase once again, fix all of them, find some more. Your helps as always is appreciated :) |
…6/jwt into issues/113_PayLoadBuilder
Wow, we did it. Big thanks to @paule96 for your contribution! |
Pushed to NuGet as 3.2.0-beta |
Hey developers, I'm happy to see this code now in the main repo! Thanks to all your feedback. 👍 |
Start the work on a fluent-API to decode und create a JWT.