diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs
index ae1e4d97ad..c18317f830 100644
--- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs
+++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs
@@ -3,6 +3,8 @@
using System;
using Microsoft.AspNet.Authentication;
+using Microsoft.Framework.Internal;
+using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Builder
{
@@ -15,12 +17,34 @@ namespace Microsoft.AspNet.Builder
/// Adds a claims transformation middleware to your web application pipeline.
///
/// The IApplicationBuilder passed to your configuration method
- /// Used to configure the options for the middleware
- /// The name of the options class that controls the middleware behavior, null will use the default options
/// The original app parameter
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app)
{
- return app.UseMiddleware();
+ return app.UseClaimsTransformation(configureOptions: o => { }, optionsName: string.Empty);
+ }
+
+ ///
+ /// Adds a claims transformation middleware to your web application pipeline.
+ ///
+ /// The IApplicationBuilder passed to your configuration method
+ /// Used to configure the options for the middleware
+ /// The original app parameter
+ public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action configureOptions)
+ {
+ return app.UseClaimsTransformation(configureOptions: configureOptions, optionsName: string.Empty);
+ }
+
+ ///
+ /// Adds a claims transformation middleware to your web application pipeline.
+ ///
+ /// The IApplicationBuilder passed to your configuration method
+ /// Used to configure the options for the middleware
+ /// The name of the options class that controls the middleware behavior, null will use the default options
+ /// The original app parameter
+ public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action configureOptions, [NotNull] string optionsName)
+ {
+ return app.UseMiddleware(
+ new ConfigureOptions(configureOptions) { Name = optionsName });
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs
index a8022d576a..0f785161c4 100644
--- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs
+++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs
@@ -15,10 +15,18 @@ namespace Microsoft.AspNet.Authentication
public ClaimsTransformationMiddleware(
[NotNull] RequestDelegate next,
- [NotNull] IOptions options)
+ [NotNull] IOptions options,
+ ConfigureOptions configureOptions)
{
- // REVIEW: do we need to take ConfigureOptions??
- Options = options.Options;
+ if (configureOptions != null)
+ {
+ Options = options.GetNamedOptions(configureOptions.Name);
+ configureOptions.Configure(Options, configureOptions.Name);
+ }
+ else
+ {
+ Options = options.Options;
+ }
_next = next;
}
diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs
index 7e1dc417b1..0b02b78e91 100644
--- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs
+++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs
@@ -461,7 +461,16 @@ namespace Microsoft.AspNet.Authentication.Google
options.AutomaticAuthentication = true;
});
app.UseGoogleAuthentication(configureOptions);
- app.UseClaimsTransformation();
+ app.UseClaimsTransformation(o =>
+ {
+ o.Transformation = p =>
+ {
+ var id = new ClaimsIdentity("xform");
+ id.AddClaim(new Claim("xform", "yup"));
+ p.AddIdentity(id);
+ return p;
+ };
+ });
app.Use(async (context, next) =>
{
var req = context.Request;
@@ -508,13 +517,6 @@ namespace Microsoft.AspNet.Authentication.Google
{
options.SignInScheme = TestExtensions.CookieAuthenticationScheme;
});
- services.ConfigureClaimsTransformation(p =>
- {
- var id = new ClaimsIdentity("xform");
- id.AddClaim(new Claim("xform", "yup"));
- p.AddIdentity(id);
- return p;
- });
});
}