#413 Rename OAuthBearer to JwtBearer.

This commit is contained in:
Chris R 2015-09-01 12:23:51 -07:00
parent 561c997cb2
commit bcf8a45340
17 changed files with 97 additions and 97 deletions

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.22605.0 VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D2B6A51-2F9F-44F5-8131-EA5CAC053652}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D2B6A51-2F9F-44F5-8131-EA5CAC053652}"
EndProject EndProject
@ -40,7 +40,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentica
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentication.Test", "test\Microsoft.AspNet.Authentication.Test\Microsoft.AspNet.Authentication.Test.xproj", "{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentication.Test", "test\Microsoft.AspNet.Authentication.Test\Microsoft.AspNet.Authentication.Test.xproj", "{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B}"
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentication.OAuthBearer", "src\Microsoft.AspNet.Authentication.OAuthBearer\Microsoft.AspNet.Authentication.OAuthBearer.xproj", "{2755BFE5-7421-4A31-A644-F817DF5CAA98}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentication.JwtBearer", "src\Microsoft.AspNet.Authentication.JwtBearer\Microsoft.AspNet.Authentication.JwtBearer.xproj", "{2755BFE5-7421-4A31-A644-F817DF5CAA98}"
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authorization.Test", "test\Microsoft.AspNet.Authorization.Test\Microsoft.AspNet.Authorization.Test.xproj", "{7AF5AD96-EB6E-4D0E-8ABE-C0B543C0F4C2}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authorization.Test", "test\Microsoft.AspNet.Authorization.Test\Microsoft.AspNet.Authorization.Test.xproj", "{7AF5AD96-EB6E-4D0E-8ABE-C0B543C0F4C2}"
EndProject EndProject

View File

@ -2,16 +2,16 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.Authentication.OAuthBearer; using Microsoft.AspNet.Authentication.JwtBearer;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
/// <summary> /// <summary>
/// Extension methods to add OAuth Bearer authentication capabilities to an HTTP application pipeline /// Extension methods to add Jwt Bearer authentication capabilities to an HTTP application pipeline
/// </summary> /// </summary>
public static class OAuthBearerAppBuilderExtensions public static class JwtBearerAppBuilderExtensions
{ {
/// <summary> /// <summary>
/// Adds Bearer token processing to an HTTP application pipeline. This middleware understands appropriately /// Adds Bearer token processing to an HTTP application pipeline. This middleware understands appropriately
@ -24,10 +24,10 @@ namespace Microsoft.AspNet.Builder
/// <param name="app">The application builder</param> /// <param name="app">The application builder</param>
/// <param name="options">Options which control the processing of the bearer header.</param> /// <param name="options">Options which control the processing of the bearer header.</param>
/// <returns>The application builder</returns> /// <returns>The application builder</returns>
public static IApplicationBuilder UseOAuthBearerAuthentication([NotNull] this IApplicationBuilder app, Action<OAuthBearerAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action<JwtBearerAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<OAuthBearerAuthenticationMiddleware>( return app.UseMiddleware<JwtBearerAuthenticationMiddleware>(
new ConfigureOptions<OAuthBearerAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<JwtBearerAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -1,16 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
/// <summary> /// <summary>
/// Default values used by authorization server and bearer authentication. /// Default values used by authorization server and bearer authentication.
/// </summary> /// </summary>
public static class OAuthBearerAuthenticationDefaults public static class JwtBearerAuthenticationDefaults
{ {
/// <summary> /// <summary>
/// Default value for AuthenticationScheme property in the OAuthBearerAuthenticationOptions and /// Default value for AuthenticationScheme property in the JwtBearerAuthenticationOptions and
/// OAuthAuthorizationServerOptions. /// JwtAuthorizationServerOptions.
/// </summary> /// </summary>
public const string AuthenticationScheme = "Bearer"; public const string AuthenticationScheme = "Bearer";
} }

View File

@ -11,9 +11,9 @@ using Microsoft.AspNet.Http.Features.Authentication;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
public class OAuthBearerAuthenticationHandler : AuthenticationHandler<OAuthBearerAuthenticationOptions> public class JwtBearerAuthenticationHandler : AuthenticationHandler<JwtBearerAuthenticationOptions>
{ {
private OpenIdConnectConfiguration _configuration; private OpenIdConnectConfiguration _configuration;
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
{ {
// Give application opportunity to find from a different location, adjust, or reject token // Give application opportunity to find from a different location, adjust, or reject token
var messageReceivedNotification = var messageReceivedNotification =
new MessageReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options) new MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
{ {
ProtocolMessage = Context, ProtocolMessage = Context,
}; };
@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
// notify user token was received // notify user token was received
var securityTokenReceivedNotification = var securityTokenReceivedNotification =
new SecurityTokenReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options) new SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
{ {
ProtocolMessage = Context, ProtocolMessage = Context,
SecurityToken = token, SecurityToken = token,
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
{ {
var principal = validator.ValidateToken(token, validationParameters, out validatedToken); var principal = validator.ValidateToken(token, validationParameters, out validatedToken);
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme); var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme);
var securityTokenValidatedNotification = new SecurityTokenValidatedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options) var securityTokenValidatedNotification = new SecurityTokenValidatedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
{ {
ProtocolMessage = Context, ProtocolMessage = Context,
AuthenticationTicket = ticket AuthenticationTicket = ticket
@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
} }
var authenticationFailedNotification = var authenticationFailedNotification =
new AuthenticationFailedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options) new AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
{ {
ProtocolMessage = Context, ProtocolMessage = Context,
Exception = ex Exception = ex
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context) protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
{ {
Response.StatusCode = 401; Response.StatusCode = 401;
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<OAuthBearerAuthenticationOptions>(Context, Options)); await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>(Context, Options));
return false; return false;
} }

View File

@ -12,31 +12,31 @@ using Microsoft.Framework.WebEncoders;
using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
/// <summary> /// <summary>
/// Bearer authentication middleware component which is added to an HTTP pipeline. This class is not /// Bearer authentication middleware component which is added to an HTTP pipeline. This class is not
/// created by application code directly, instead it is added by calling the the IAppBuilder UseOAuthBearerAuthentication /// created by application code directly, instead it is added by calling the the IAppBuilder UseJwtBearerAuthentication
/// extension method. /// extension method.
/// </summary> /// </summary>
public class OAuthBearerAuthenticationMiddleware : AuthenticationMiddleware<OAuthBearerAuthenticationOptions> public class JwtBearerAuthenticationMiddleware : AuthenticationMiddleware<JwtBearerAuthenticationOptions>
{ {
/// <summary> /// <summary>
/// Bearer authentication component which is added to an HTTP pipeline. This constructor is not /// Bearer authentication component which is added to an HTTP pipeline. This constructor is not
/// called by application code directly, instead it is added by calling the the IAppBuilder UseOAuthBearerAuthentication /// called by application code directly, instead it is added by calling the the IAppBuilder UseJwtBearerAuthentication
/// extension method. /// extension method.
/// </summary> /// </summary>
public OAuthBearerAuthenticationMiddleware( public JwtBearerAuthenticationMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<OAuthBearerAuthenticationOptions> options, [NotNull] IOptions<JwtBearerAuthenticationOptions> options,
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions) ConfigureOptions<JwtBearerAuthenticationOptions> configureOptions)
: base(next, options, loggerFactory, encoder, configureOptions) : base(next, options, loggerFactory, encoder, configureOptions)
{ {
if (Options.Notifications == null) if (Options.Notifications == null)
{ {
Options.Notifications = new OAuthBearerAuthenticationNotifications(); Options.Notifications = new JwtBearerAuthenticationNotifications();
} }
if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.Audience)) if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.Audience))
@ -76,13 +76,13 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
/// Called by the AuthenticationMiddleware base class to create a per-request handler. /// Called by the AuthenticationMiddleware base class to create a per-request handler.
/// </summary> /// </summary>
/// <returns>A new instance of the request handler</returns> /// <returns>A new instance of the request handler</returns>
protected override AuthenticationHandler<OAuthBearerAuthenticationOptions> CreateHandler() protected override AuthenticationHandler<JwtBearerAuthenticationOptions> CreateHandler()
{ {
return new OAuthBearerAuthenticationHandler(); return new JwtBearerAuthenticationHandler();
} }
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")] [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")]
private static HttpMessageHandler ResolveHttpMessageHandler(OAuthBearerAuthenticationOptions options) private static HttpMessageHandler ResolveHttpMessageHandler(JwtBearerAuthenticationOptions options)
{ {
HttpMessageHandler handler = options.BackchannelHttpHandler ?? HttpMessageHandler handler = options.BackchannelHttpHandler ??
#if DNX451 #if DNX451

View File

@ -9,19 +9,19 @@ using System.Net.Http;
using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
/// <summary> /// <summary>
/// Options class provides information needed to control Bearer Authentication middleware behavior /// Options class provides information needed to control Bearer Authentication middleware behavior
/// </summary> /// </summary>
public class OAuthBearerAuthenticationOptions : AuthenticationOptions public class JwtBearerAuthenticationOptions : AuthenticationOptions
{ {
/// <summary> /// <summary>
/// Creates an instance of bearer authentication options with default values. /// Creates an instance of bearer authentication options with default values.
/// </summary> /// </summary>
public OAuthBearerAuthenticationOptions() : base() public JwtBearerAuthenticationOptions() : base()
{ {
AuthenticationScheme = OAuthBearerAuthenticationDefaults.AuthenticationScheme; AuthenticationScheme = JwtBearerAuthenticationDefaults.AuthenticationScheme;
} }
/// <summary> /// <summary>
@ -45,14 +45,14 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
/// <summary> /// <summary>
/// Gets or sets the challenge to put in the "WWW-Authenticate" header. /// Gets or sets the challenge to put in the "WWW-Authenticate" header.
/// </summary> /// </summary>
public string Challenge { get; set; } = OAuthBearerAuthenticationDefaults.AuthenticationScheme; public string Challenge { get; set; } = JwtBearerAuthenticationDefaults.AuthenticationScheme;
/// <summary> /// <summary>
/// The object provided by the application to process events raised by the bearer authentication middleware. /// The object provided by the application to process events raised by the bearer authentication middleware.
/// The application may implement the interface fully, or it may create an instance of OAuthBearerAuthenticationProvider /// The application may implement the interface fully, or it may create an instance of JwtBearerAuthenticationProvider
/// and assign delegates only to the events it wants to process. /// and assign delegates only to the events it wants to process.
/// </summary> /// </summary>
public OAuthBearerAuthenticationNotifications Notifications { get; set; } = new OAuthBearerAuthenticationNotifications(); public JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications();
/// <summary> /// <summary>
/// The HttpMessageHandler used to retrieve metadata. /// The HttpMessageHandler used to retrieve metadata.

View File

@ -0,0 +1,36 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Authentication.JwtBearer;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
/// <summary>
/// Extension methods to add Jwt Bearer authentication capabilities to an HTTP application pipeline
/// </summary>
public static class JwtBearerServiceCollectionExtensions
{
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerAuthenticationOptions> configure)
{
return services.ConfigureJwtBearerAuthentication(configure, optionsName: "");
}
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerAuthenticationOptions> configure, string optionsName)
{
return services.Configure(configure, optionsName);
}
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
{
return services.ConfigureJwtBearerAuthentication(config, optionsName: "");
}
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName)
{
return services.Configure<JwtBearerAuthenticationOptions>(config, optionsName);
}
}
}

View File

@ -3,7 +3,7 @@
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
public class AuthenticationChallengeNotification<TOptions> : BaseNotification<TOptions> public class AuthenticationChallengeNotification<TOptions> : BaseNotification<TOptions>
{ {

View File

@ -6,19 +6,19 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
/// <summary> /// <summary>
/// Specifies events which the <see cref="OAuthBearerAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. /> /// Specifies events which the <see cref="JwtBearerAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
/// </summary> /// </summary>
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
/// <summary> /// <summary>
/// OAuth bearer token middleware provider /// Jwt bearer token middleware provider
/// </summary> /// </summary>
public class OAuthBearerAuthenticationNotifications public class JwtBearerAuthenticationNotifications
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OAuthBearerAuthenticationProvider"/> class /// Initializes a new instance of the <see cref="JwtBearerAuthenticationProvider"/> class
/// </summary> /// </summary>
public OAuthBearerAuthenticationNotifications() public JwtBearerAuthenticationNotifications()
{ {
ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); }; ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); };
AuthenticationFailed = notification => Task.FromResult(0); AuthenticationFailed = notification => Task.FromResult(0);
@ -30,26 +30,26 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
/// <summary> /// <summary>
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
/// </summary> /// </summary>
public Func<AuthenticationFailedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; } public Func<AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
/// <summary> /// <summary>
/// Invoked when a protocol message is first received. /// Invoked when a protocol message is first received.
/// </summary> /// </summary>
public Func<MessageReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> MessageReceived { get; set; } public Func<MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
/// <summary> /// <summary>
/// Invoked with the security token that has been extracted from the protocol message. /// Invoked with the security token that has been extracted from the protocol message.
/// </summary> /// </summary>
public Func<SecurityTokenReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; } public Func<SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
/// <summary> /// <summary>
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated. /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
/// </summary> /// </summary>
public Func<SecurityTokenValidatedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; } public Func<SecurityTokenValidatedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
/// <summary> /// <summary>
/// Invoked to apply a challenge sent back to the caller. /// Invoked to apply a challenge sent back to the caller.
/// </summary> /// </summary>
public Func<AuthenticationChallengeNotification<OAuthBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; } public Func<AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
} }
} }

View File

@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Microsoft.AspNet.Authentication.OAuthBearer { namespace Microsoft.AspNet.Authentication.JwtBearer {
using System; using System;
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.OAuth.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.Jwt.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;

View File

@ -1,6 +1,6 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"description": "ASP.NET 5 middleware that enables an application to receive a OAuth bearer token.", "description": "ASP.NET 5 middleware that enables an application to receive a Jwt bearer token.",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/aspnet/security" "url": "git://github.com/aspnet/security"

View File

@ -1,36 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Authentication.OAuthBearer;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
/// <summary>
/// Extension methods to add OAuth Bearer authentication capabilities to an HTTP application pipeline
/// </summary>
public static class OAuthBearerServiceCollectionExtensions
{
public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OAuthBearerAuthenticationOptions> configure)
{
return services.ConfigureOAuthBearerAuthentication(configure, optionsName: "");
}
public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OAuthBearerAuthenticationOptions> configure, string optionsName)
{
return services.Configure(configure, optionsName);
}
public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
{
return services.ConfigureOAuthBearerAuthentication(config, optionsName: "");
}
public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName)
{
return services.Configure<OAuthBearerAuthenticationOptions>(config, optionsName);
}
}
}

View File

@ -16,9 +16,9 @@ using Microsoft.Framework.DependencyInjection;
using Shouldly; using Shouldly;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Authentication.OAuthBearer namespace Microsoft.AspNet.Authentication.JwtBearer
{ {
public class OAuthBearerMiddlewareTests public class JwtBearerMiddlewareTests
{ {
[Fact] [Fact]
public async Task BearerTokenValidation() public async Task BearerTokenValidation()
@ -309,13 +309,13 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
} }
} }
private static TestServer CreateServer(Action<OAuthBearerAuthenticationOptions> configureOptions, Func<HttpContext, bool> handler = null) private static TestServer CreateServer(Action<JwtBearerAuthenticationOptions> configureOptions, Func<HttpContext, bool> handler = null)
{ {
return TestServer.Create(app => return TestServer.Create(app =>
{ {
if (configureOptions != null) if (configureOptions != null)
{ {
app.UseOAuthBearerAuthentication(configureOptions); app.UseJwtBearerAuthentication(configureOptions);
} }
app.Use(async (context, next) => app.Use(async (context, next) =>
@ -345,17 +345,17 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
else if (context.Request.Path == new PathString("/unauthorized")) else if (context.Request.Path == new PathString("/unauthorized"))
{ {
// Simulate Authorization failure // Simulate Authorization failure
var result = await context.Authentication.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); var result = await context.Authentication.AuthenticateAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
await context.Authentication.ChallengeAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); await context.Authentication.ChallengeAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
} }
else if (context.Request.Path == new PathString("/signIn")) else if (context.Request.Path == new PathString("/signIn"))
{ {
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignInAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal())); await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignInAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal()));
} }
else if (context.Request.Path == new PathString("/signOut")) else if (context.Request.Path == new PathString("/signOut"))
{ {
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme)); await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme));
} }
else else
{ {

View File

@ -6,8 +6,8 @@
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
"Microsoft.AspNet.Authentication.Google": "1.0.0-*", "Microsoft.AspNet.Authentication.Google": "1.0.0-*",
"Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-*",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*", "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-*",
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*", "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
"Microsoft.AspNet.DataProtection": "1.0.0-*", "Microsoft.AspNet.DataProtection": "1.0.0-*",