// 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 System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Authentication;
namespace Microsoft.AspNet.Builder
{
///
/// Extension methods to add claims transformation capabilities to an HTTP application pipeline.
///
public static class ClaimsTransformationAppBuilderExtensions
{
///
/// Adds the middleware to the specified , which enables claims transformation capabilities.
///
/// The to add the middleware to.
/// A that specifies options for the middleware.
/// A reference to this instance after the operation has completed.
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, ClaimsTransformationOptions options)
{
return app.UseMiddleware(options);
}
///
/// Adds the middleware to the specified , which enables claims transformation capabilities.
///
/// The to add the middleware to.
/// A function that asynchronously transforms one to another.
/// A reference to this instance after the operation has completed.
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Func> transform)
{
var options = new ClaimsTransformationOptions();
options.Transformer = new ClaimsTransformer
{
OnTransform = transform
};
return app.UseClaimsTransformation(options);
}
///
/// Adds the middleware to the specified , which enables claims transformation capabilities.
///
/// The to add the middleware to.
/// An action delegate to configure the provided .
/// A reference to this instance after the operation has completed.
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Action configureOptions)
{
var options = new ClaimsTransformationOptions();
if (configureOptions != null)
{
configureOptions(options);
}
return app.UseClaimsTransformation(options);
}
}
}