Last active
October 20, 2016 00:58
-
-
Save tugberkugurlu/a8cd70ebc14d2d09e5a4a378bfcd95ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClaimsPrincipalParameterBinding : HttpParameterBinding | |
{ | |
public ClaimsPrincipalParameterBinding(HttpParameterDescriptor descriptor) | |
: base(descriptor) | |
{ | |
} | |
public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) | |
{ | |
ClaimsPrincipal claimsPrincipal = actionContext.Request.GetRequestContext().Principal as ClaimsPrincipal; | |
actionContext.ActionArguments.Add(Descriptor.ParameterName, claimsPrincipal); | |
return TaskHelpers.Completed(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Configure(HttpConfiguration configuration) | |
{ | |
ConfigureParameterBindingRules(configuration.ParameterBindingRules); | |
} | |
private static void ConfigureParameterBindingRules(ParameterBindingRulesCollection bindingRules) | |
{ | |
// If the parameter type is ClaimsPrincipal, use ClaimsPrincipalParameterBinding. | |
bindingRules.Add(typeof(ClaimsPrincipal), descriptor => new ClaimsPrincipalParameterBinding(descriptor)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment