, -API (. Toan). , -api Autodesk Forms . , , .
http://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-api
-. , . , , . , ASP.NET Web API, MVC , .
, -. Web API (Get, Post, Put, Delete, Options), Controller.User IPrincipal, , IsAuthenticated bool . , [AllowAnonymous] [Authorize].
: SSL - , . Auth
, MVC4 -API BaseApiController
public BaseApiController()
{
CurrentUser = new ScrubbedUser(User);
}
protected ScrubbedUser CurrentUser { get; set; }
ScrubbedUser ( /), ,
public class ScrubbedUser
{
private IPrincipal Principal { get; set; }
public ScrubbedUser(string principal)
{
Principal = null;
if (string.IsNullOrEmpty(principal))
{
Profile = GetDefaultProfile();
}
else
{
Profile = GetUserProfile(principal);
}
Memberships = GetUserMemberships();
Settings = GetUserSettings();
}
public SurgeStreetUser(IPrincipal principal)
{
Principal = principal;
if (Principal == null
|| Principal.Identity == null
|| Principal.Identity.IsAuthenticated == false
|| string.IsNullOrEmpty(Principal.Identity.Name))
{
Profile = GetDefaultProfile();
}
else
{
Profile = GetUserProfile(Principal.Identity.Name);
}
Memberships = GetUserMemberships();
Settings = GetUserSettings();
}
public UserProfile Profile { get; private set; }
public List<V_UserMembership> Memberships { get; private set; }
public List<Setting> Settings { get; private set; }
private UserProfile GetDefaultProfile()
{
}
private UserProfile GetUserProfile(string userName)
{
}
private List<V_UserMembership> GetUserMemberships()
{
}
private UserProfile PopulateCurrentUser(UserProfile userProfile)
{
var user = new UserProfile
{
};
return user;
}
private List<Setting> GetUserSettings()
{
}
private dynamic JSONRecord
{
get
{
return new
{
CustId = Profile.CustId,
UserName = Profile.UserName,
UserId = Profile.UserId,
Email = Profile.Email,
FirstName = Profile.FirstName,
Language = Profile.Language,
LastActivityDate = Profile.LastActivityDate,
LastName = Profile.LastName,
DebugOption = Profile.DebugOption,
Device = Profile.Device,
Memberships = Memberships,
Settings = Settings
};
}
}
}
CurrentUser , , -. [] -API
public class ListController : BaseApiController
{
public dynamic Get(string id)
{
if (CurrentUser.Profile.CustId == "public")
{
return HttpStatusCode.Forbidden;
}
if (!User.Identity.IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string filterExt = string.IsNullOrEmpty(id) || id=="global"
? "*" : id;
return ListRepository.GetList(filterExt, SSUser);
}
[Authorize]
public dynamic Post(JObject values)
{
return CurrentUser.JSONRecord;
}
}