// 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.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.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 reference to this instance after the operation has completed.
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMiddleware();
}
///
/// 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)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (transform == null)
{
throw new ArgumentNullException(nameof(transform));
}
return app.UseClaimsTransformation(new ClaimsTransformationOptions
{
Transformer = new ClaimsTransformer { OnTransform = transform }
});
}
///
/// Adds the middleware to the specified , which enables claims transformation capabilities.
///
/// The to add the middleware to.
/// The to configure the middleware with.
/// A reference to this instance after the operation has completed.
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, ClaimsTransformationOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware(Options.Create(options));
}
}
}