#413 Rename OAuthBearer to JwtBearer.
This commit is contained in:
parent
561c997cb2
commit
bcf8a45340
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.22605.0
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D2B6A51-2F9F-44F5-8131-EA5CAC053652}"
|
||||
EndProject
|
||||
|
|
@ -40,7 +40,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentica
|
|||
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}"
|
||||
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
// 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.AspNet.Authentication.JwtBearer;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <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>
|
||||
public static class OAuthBearerAppBuilderExtensions
|
||||
public static class JwtBearerAppBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 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="options">Options which control the processing of the bearer header.</param>
|
||||
/// <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>(
|
||||
new ConfigureOptions<OAuthBearerAuthenticationOptions>(configureOptions ?? (o => { }))
|
||||
return app.UseMiddleware<JwtBearerAuthenticationMiddleware>(
|
||||
new ConfigureOptions<JwtBearerAuthenticationOptions>(configureOptions ?? (o => { }))
|
||||
{
|
||||
Name = optionsName
|
||||
});
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
// 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.
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
/// <summary>
|
||||
/// Default values used by authorization server and bearer authentication.
|
||||
/// </summary>
|
||||
public static class OAuthBearerAuthenticationDefaults
|
||||
public static class JwtBearerAuthenticationDefaults
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value for AuthenticationScheme property in the OAuthBearerAuthenticationOptions and
|
||||
/// OAuthAuthorizationServerOptions.
|
||||
/// Default value for AuthenticationScheme property in the JwtBearerAuthenticationOptions and
|
||||
/// JwtAuthorizationServerOptions.
|
||||
/// </summary>
|
||||
public const string AuthenticationScheme = "Bearer";
|
||||
}
|
||||
|
|
@ -11,9 +11,9 @@ using Microsoft.AspNet.Http.Features.Authentication;
|
|||
using Microsoft.Framework.Logging;
|
||||
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;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
{
|
||||
// Give application opportunity to find from a different location, adjust, or reject token
|
||||
var messageReceivedNotification =
|
||||
new MessageReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options)
|
||||
new MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||
{
|
||||
ProtocolMessage = Context,
|
||||
};
|
||||
|
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
|
||||
// notify user token was received
|
||||
var securityTokenReceivedNotification =
|
||||
new SecurityTokenReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options)
|
||||
new SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||
{
|
||||
ProtocolMessage = Context,
|
||||
SecurityToken = token,
|
||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
{
|
||||
var principal = validator.ValidateToken(token, validationParameters, out validatedToken);
|
||||
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,
|
||||
AuthenticationTicket = ticket
|
||||
|
|
@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
}
|
||||
|
||||
var authenticationFailedNotification =
|
||||
new AuthenticationFailedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options)
|
||||
new AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||
{
|
||||
ProtocolMessage = Context,
|
||||
Exception = ex
|
||||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
||||
{
|
||||
Response.StatusCode = 401;
|
||||
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<OAuthBearerAuthenticationOptions>(Context, Options));
|
||||
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>(Context, Options));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -12,31 +12,31 @@ using Microsoft.Framework.WebEncoders;
|
|||
using Microsoft.IdentityModel.Protocols;
|
||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class OAuthBearerAuthenticationMiddleware : AuthenticationMiddleware<OAuthBearerAuthenticationOptions>
|
||||
public class JwtBearerAuthenticationMiddleware : AuthenticationMiddleware<JwtBearerAuthenticationOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public OAuthBearerAuthenticationMiddleware(
|
||||
public JwtBearerAuthenticationMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<OAuthBearerAuthenticationOptions> options,
|
||||
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
|
||||
[NotNull] IOptions<JwtBearerAuthenticationOptions> options,
|
||||
ConfigureOptions<JwtBearerAuthenticationOptions> configureOptions)
|
||||
: base(next, options, loggerFactory, encoder, configureOptions)
|
||||
{
|
||||
if (Options.Notifications == null)
|
||||
{
|
||||
Options.Notifications = new OAuthBearerAuthenticationNotifications();
|
||||
Options.Notifications = new JwtBearerAuthenticationNotifications();
|
||||
}
|
||||
|
||||
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.
|
||||
/// </summary>
|
||||
/// <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")]
|
||||
private static HttpMessageHandler ResolveHttpMessageHandler(OAuthBearerAuthenticationOptions options)
|
||||
private static HttpMessageHandler ResolveHttpMessageHandler(JwtBearerAuthenticationOptions options)
|
||||
{
|
||||
HttpMessageHandler handler = options.BackchannelHttpHandler ??
|
||||
#if DNX451
|
||||
|
|
@ -9,19 +9,19 @@ using System.Net.Http;
|
|||
using Microsoft.IdentityModel.Protocols;
|
||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
/// <summary>
|
||||
/// Options class provides information needed to control Bearer Authentication middleware behavior
|
||||
/// </summary>
|
||||
public class OAuthBearerAuthenticationOptions : AuthenticationOptions
|
||||
public class JwtBearerAuthenticationOptions : AuthenticationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of bearer authentication options with default values.
|
||||
/// </summary>
|
||||
public OAuthBearerAuthenticationOptions() : base()
|
||||
public JwtBearerAuthenticationOptions() : base()
|
||||
{
|
||||
AuthenticationScheme = OAuthBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
AuthenticationScheme = JwtBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -45,14 +45,14 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
/// <summary>
|
||||
/// Gets or sets the challenge to put in the "WWW-Authenticate" header.
|
||||
/// </summary>
|
||||
public string Challenge { get; set; } = OAuthBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
public string Challenge { get; set; } = JwtBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public OAuthBearerAuthenticationNotifications Notifications { get; set; } = new OAuthBearerAuthenticationNotifications();
|
||||
public JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications();
|
||||
|
||||
/// <summary>
|
||||
/// The HttpMessageHandler used to retrieve metadata.
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class AuthenticationChallengeNotification<TOptions> : BaseNotification<TOptions>
|
||||
{
|
||||
|
|
@ -6,19 +6,19 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
|
||||
/// <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>
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth bearer token middleware provider
|
||||
/// Jwt bearer token middleware provider
|
||||
/// </summary>
|
||||
public class OAuthBearerAuthenticationNotifications
|
||||
public class JwtBearerAuthenticationNotifications
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OAuthBearerAuthenticationProvider"/> class
|
||||
/// Initializes a new instance of the <see cref="JwtBearerAuthenticationProvider"/> class
|
||||
/// </summary>
|
||||
public OAuthBearerAuthenticationNotifications()
|
||||
public JwtBearerAuthenticationNotifications()
|
||||
{
|
||||
ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); };
|
||||
AuthenticationFailed = notification => Task.FromResult(0);
|
||||
|
|
@ -30,26 +30,26 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
/// </summary>
|
||||
public Func<AuthenticationFailedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
||||
public Func<AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a protocol message is first received.
|
||||
/// </summary>
|
||||
public Func<MessageReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
|
||||
public Func<MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked with the security token that has been extracted from the protocol message.
|
||||
/// </summary>
|
||||
public Func<SecurityTokenReceivedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
||||
public Func<SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
||||
/// </summary>
|
||||
public Func<SecurityTokenValidatedNotification<HttpContext, OAuthBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
||||
public Func<SecurityTokenValidatedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked to apply a challenge sent back to the caller.
|
||||
/// </summary>
|
||||
public Func<AuthenticationChallengeNotification<OAuthBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
|
||||
public Func<AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer {
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer {
|
||||
using System;
|
||||
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer {
|
|||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
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;
|
||||
}
|
||||
return resourceMan;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/aspnet/security"
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,9 @@ using Microsoft.Framework.DependencyInjection;
|
|||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class OAuthBearerMiddlewareTests
|
||||
public class JwtBearerMiddlewareTests
|
||||
{
|
||||
[Fact]
|
||||
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 =>
|
||||
{
|
||||
if (configureOptions != null)
|
||||
{
|
||||
app.UseOAuthBearerAuthentication(configureOptions);
|
||||
app.UseJwtBearerAuthentication(configureOptions);
|
||||
}
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
|
|
@ -345,17 +345,17 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
|||
else if (context.Request.Path == new PathString("/unauthorized"))
|
||||
{
|
||||
// Simulate Authorization failure
|
||||
var result = await context.Authentication.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
await context.Authentication.ChallengeAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
var result = await context.Authentication.AuthenticateAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
await context.Authentication.ChallengeAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -6,8 +6,8 @@
|
|||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Facebook": "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.OAuthBearer": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||
|
|
|
|||
Loading…
Reference in New Issue