Skip to content
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

Using single overload of WithSecret() but with params #162

Merged
merged 2 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions JWT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
.gitignore = .gitignore
JWT.sln.DotSettings = JWT.sln.DotSettings
NuGet.config = NuGet.config
README.md = README.md
EndProjectSection
EndProject
Expand Down
19 changes: 19 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<settings>
<repositoryPath>$(SolutionDir)\packages</repositoryPath>
</settings>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
<packageSources>
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<activePackageSource>
<!-- All non-disabled sources are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</packageRestore>
</configuration>
18 changes: 2 additions & 16 deletions src/JWT/Builder/JwtBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,7 @@ public JwtBuilder WithAlgorithm(IJwtAlgorithm algorithm)
/// Required to create new token that uses an asymmetric algorithm such as <seealso cref="RS256Algorithm" />.
/// </remarks>
/// <returns>Current builder instance</returns>
public JwtBuilder WithSecret(string secret)
{
_secrets = new[] { secret };
return this;
}

/// <summary>
/// Sets certificates secrets.
/// </summary>
/// <remarks>
/// Required to create new token that uses an asymmetric algorithm such as <seealso cref="RS256Algorithm" />.
/// </remarks>
/// <returns>Current builder instance</returns>
public JwtBuilder WithSecrets(string[] secrets)
public JwtBuilder WithSecret(params string[] secrets)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codingmate what would you say?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way better.
How did I miss that, duh 😃

{
_secrets = secrets;
return this;
Expand Down Expand Up @@ -287,8 +274,7 @@ private void EnsureCanBuild()
$"-{nameof(WithUrlEncoder)}.");

if (!HasOnlyOneSecret())
throw new InvalidOperationException("You can't provide more than one secret to use for encoding." +
$" You should use {nameof(WithSecret)} instead of {nameof(WithSecrets)}.");
throw new InvalidOperationException("You can't provide more than one secret to use for encoding.");
}

private void EnsureCanDecode()
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/JWT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageProjectUrl>https://github.com/jwt-dotnet/jwt</PackageProjectUrl>
<Authors>John Sheehan, Michael Lehenbauer, Alexander Batishchev</Authors>
<PackageLicenseUrl>https://creativecommons.org/publicdomain/zero/1.0/</PackageLicenseUrl>
<Version>5.0.0-beta1</Version>
<Version>5.0.0-beta2</Version>
<PackageTags>jwt json</PackageTags>
<FileVersion>5.0.0.0</FileVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
Expand Down
4 changes: 2 additions & 2 deletions tests/JWT.Tests.Common/JwtBuilderDecodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void DecodeToken_WithVerifySignature()
public void DecodeToken_WithVerifySignature_MultipleSecrets()
{
var payload = new JwtBuilder()
.WithSecrets(_sampleSecrets)
.WithSecret(_sampleSecrets)
.MustVerifySignature()
.Decode(_sampleToken);

Expand Down Expand Up @@ -149,7 +149,7 @@ public void DecodeToken_ToDictionary()
public void DecodeToken_ToDictionary_MultipleSecrets()
{
var payload = new JwtBuilder()
.WithSecrets(_sampleSecrets)
.WithSecret(_sampleSecrets)
.MustVerifySignature()
.Decode<Dictionary<string, string>>(_sampleToken);

Expand Down
2 changes: 1 addition & 1 deletion tests/JWT.Tests.Common/JwtBuilderEncodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Build_WithoutAlgorithm_WithSecret_Should_Throw_Exception()
public void Build_WithMultipleSecrets_Should_Throw_Exception()
{
Assert.Throws<InvalidOperationException>(() => new JwtBuilder()
.WithSecrets(new []{ "fjhsdghflghlk", "wrouhsfjkghure"})
.WithSecret(new []{ "fjhsdghflghlk", "wrouhsfjkghure"})
.Build());
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/JWT.Tests.Core/JWT.Tests.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
Expand Down
2 changes: 1 addition & 1 deletion tests/JWT.Tests.NETFramework/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="xunit" version="2.3.1" targetFramework="net462" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net462" />
<package id="xunit.analyzers" version="0.7.0" targetFramework="net462" />
<package id="xunit.analyzers" version="0.8.0" targetFramework="net462" />
<package id="xunit.assert" version="2.3.1" targetFramework="net462" />
<package id="xunit.core" version="2.3.1" targetFramework="net462" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net462" />
Expand Down