How do you setup mixed authorizations for different authentications in .net (web api 2 + owin) -


I am quite new to .NET and I am trying to create a restfull service where you can add othe 2 Be able to login with a "General Account" From VS 2013, the SPA template allowed me to do it quickly and easily and I am very happy with it.

I am facing a different problem right now. I'm unable to find a different way to access these different types of logins. For example, I only allow users to access X and users through the Youth Authentication method which is able to only see Y for authenticating "normal methods" (even with a carrier token).

I searched the web and it looks like I should use the [authorized] tag, but I'm not sure how to customize it and there is no difference between different logins. Various ways of optimizing but no one is working and I am stumbling in solutions which are outdated.

Can anyone help?

Thank you! Public class AuthorizeExternalsOnly: AuthorizeAttribute {protected override bool}

IsAuthorized (System.Web.Http.Controllers.HttpActionContext ActionContacts) {if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) {string externalClaim = ""; Try identifying the claim as {externalClaim = (actionContext.ControllerContext.RequestContext.Principal.Identity). Testimonials FirstOrDefault (x = & gt; x.Type == Claim type. Authentication). value; } Hold (NullReferenceException) {Debug.WriteLine ("no external claim was found"); } If (External clim! = "") {Return basis. Official (Actioncorrect); } return false; } return false; }}

I added the claim on account controller GetExternalLogin

  oAuthIdentity.AddClaim (new claim (type of claim) Authentication, "external")); (...) Recognise. AddClaim (new claim (claim type authentication, "external"));   

Just before every sign.

You claim to define your user type (internal, facebook, etc.) Make a custom authoritative attribute to make decisions.

Look for some background information and link.

The code sample for custom authorization attribute, the HttpActionContext parameter lets you see which controller and the action you have taken allows you to inspect the claim collection for your user. Step through the code for different login scenarios, you will have different claims, then you can decide that your controller Whether the action is authorized for the value of a particular claim.

  Protected override bool isoofficially (system web .htp controllers.ttpapactioncontact actioncontacts) {action name = action context Action Descriptor.ActionName, ControllerName = Action Contact Controller Contube Controller descriptor ControllerName, Claims = (Identification of claims as action contracts. RequestContext.Principal.Identity). Appreciation olist ()}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -