-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ASP.NET Core, OWIN intergration packages (#231)
* Added JWT.Extensions.AspNetCore: JwtAuthenticationMiddleware (stub), JwtAuthenticationHandler * Added JWT.Extensions.AspNetCore.Tests (unit and integration) * Added JWT.Extensions.Owin: JwtAuthenticationMiddleware (stub) * Updated README, LICENSE
- Loading branch information
1 parent
5fb157a
commit cbec444
Showing
36 changed files
with
978 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Public Domain | ||
|
||
Written by John Sheehan (http://john-sheehan.com) | ||
|
||
This work is public domain. | ||
|
||
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | ||
|
||
For more information, please visit: http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
# MIT | ||
|
||
Copyright (c) 2019 Jwt.Net Maintainers and Contributors. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please visit: https://opensource.org/licenses/MIT |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<PackageProjectUrl>https://github.com/jwt-dotnet/jwt</PackageProjectUrl> | ||
<PackageReleaseNotes>https://github.com/jwt-dotnet/jwt/releases</PackageReleaseNotes> | ||
<RepositoryUrl>https://github.com/jwt-dotnet/jwt</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
|
||
<EnableSourceControlManagerQueries>$(EnableSourceLink)</EnableSourceControlManagerQueries> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
</PropertyGroup> | ||
</Project> |
25 changes: 25 additions & 0 deletions
25
src/JWT.Extensions.AspNetCore/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace JWT | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="IApplicationBuilder"/> to add the JWT authentication/authorization to the pipeline. | ||
/// </summary> | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the <see cref="JwtAuthenticationMiddleware" /> to the specified <see cref="IApplicationBuilder" />, which enables authentication/authorization using JWT. | ||
/// </summary> | ||
/// <returns> | ||
/// The <see cref="IApplicationBuilder" />. | ||
/// </returns> | ||
public static IApplicationBuilder UseJwtMiddleware(this IApplicationBuilder app) | ||
{ | ||
if (app == null) | ||
throw new ArgumentNullException(nameof(app)); | ||
|
||
return app.UseMiddleware<JwtAuthenticationMiddleware>(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/JWT.Extensions.AspNetCore/AuthenticationAppBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using JWT.Internal; | ||
using JWT.Serializers; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace JWT | ||
{ | ||
public static class AuthenticationAppBuilderExtensions | ||
{ | ||
public static AuthenticationBuilder AddJwt(this AuthenticationBuilder builder) => | ||
builder.AddJwt(JwtAuthenticationDefaults.AuthenticationScheme); | ||
|
||
public static AuthenticationBuilder AddJwt(this AuthenticationBuilder builder, string authenticationScheme) => | ||
builder.AddJwt(authenticationScheme, null); | ||
|
||
public static AuthenticationBuilder AddJwt(this AuthenticationBuilder builder, Action<JwtAuthenticationOptions> configureOptions) => | ||
builder.AddJwt(JwtAuthenticationDefaults.AuthenticationScheme, configureOptions); | ||
|
||
public static AuthenticationBuilder AddJwt(this AuthenticationBuilder builder, string authenticationScheme, Action<JwtAuthenticationOptions> configureOptions) | ||
{ | ||
builder.Services.TryAddSingleton<IJwtDecoder, JwtDecoder>(); | ||
builder.Services.TryAddSingleton<IJsonSerializer, JsonNetSerializer>(); | ||
builder.Services.TryAddSingleton<IJwtValidator, JwtValidator>(); | ||
builder.Services.TryAddSingleton<IBase64UrlEncoder, JwtBase64UrlEncoder>(); | ||
builder.Services.TryAddSingleton<IDateTimeProvider, SystemClockDatetimeProvider>(); | ||
|
||
return builder.AddScheme<JwtAuthenticationOptions, JwtAuthenticationHandler>(authenticationScheme, configureOptions); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/JWT.Extensions.AspNetCore/CertificateAuthenticationDefaults.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace JWT | ||
{ | ||
/// <summary> | ||
/// Default values related to Jwt authentication/authorization | ||
/// </summary> | ||
public static class JwtAuthenticationDefaults | ||
{ | ||
/// <summary> | ||
/// The default value used for <see cref="JwtAuthenticationOptions" />. | ||
/// </summary> | ||
public const string AuthenticationScheme = "Bearer"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/JWT.Extensions.AspNetCore/Internal/DefaultIdentityFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Security.Principal; | ||
|
||
namespace JWT.Internal | ||
{ | ||
internal static class DefaultIdentityFactory | ||
{ | ||
/// <summary> | ||
/// Creates user's identity from user's claims | ||
/// </summary> | ||
/// <param name="dic"><see cref="IDictionary{String,String}" /> of user's claims</param> | ||
/// <returns><see cref="ClaimsIdentity" /></returns> | ||
public static IIdentity CreateIdentity(IDictionary<string, string> dic) | ||
{ | ||
var claims = dic.Select(p => new Claim(p.Key, p.Value)); | ||
return new ClaimsIdentity(claims); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/JWT.Extensions.AspNetCore/Internal/DefaultTicketFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Security.Claims; | ||
using System.Security.Principal; | ||
using Microsoft.AspNetCore.Authentication; | ||
|
||
namespace JWT.Internal | ||
{ | ||
internal static class DefaultTicketFactory | ||
{ | ||
/// <summary> | ||
/// Creates user's <see cref="AuthenticationTicket" /> from user's <see cref="IIdentity" /> and current <see cref="AuthenticationScheme" /> | ||
/// </summary> | ||
public static AuthenticationTicket CreateTicket(IIdentity identity, AuthenticationScheme scheme) => | ||
new AuthenticationTicket( | ||
new ClaimsPrincipal(identity), | ||
new AuthenticationProperties(), | ||
scheme.Name); | ||
} | ||
} |
Oops, something went wrong.