Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

How to inject ClaimsPrincipal with autofac

$
0
0

Hi,

currently I am working on a single page application with durandal and breeze.
The authentification I did with the new ASP.net Identity and OAuthAuthorizationServerProvider. This work fine so far. I can excess the user in the ApiController.

But my BusinessLayer need the IPrincipal as well. I use Autofac to inject the IPrincipal. But it is always null.

Each of this code doesn't work.

            builder.Register(c => System.Security.Claims.ClaimsPrincipal.Current).As<IPrincipal>().InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<HttpRequestMessage>().GetOwinContext().Authentication.User).As<IPrincipal>().InstancePerLifetimeScope();
            builder.Register(c => HttpContext.Current.User).As<IPrincipal>().InstancePerLifetimeScope();

How can I achive this.

Thanks


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>