I have created a custom AuthorizeAttribute which verifies some OAuth credentials of user.
Once I got valid user I want to return response data to controller how can I achieve this in web api .net.
public class CustomAttribute : AuthorizeAttribute
{
protected override bool IsAuthorized(HttpActionContext actionContext)
{
var response = mydata.Result.Content.ReadAsStringAsync();
if (mydata.Result.StatusCode == HttpStatusCode.OK)
{
// return response data to controller
return true;
}
}
}
I searched I got in mvc it can be done like below.
public class CustomAttribute : AuthorizeAttribute
{
public string BlackListedUsers { get; set; }
protected override bool AuthorizeCore(AuthorizationContext filterContext)
{
filterContext.HttpContext.Items["test"] = "foo";
return true;
}
}
In controller -
_yourVariable = HttpContext.Items["test"];
How can I achieve this in System.Web.Http in web api because in webapi i do not have method AuthorizeCore and input parameter AuthorizationContext?