I am creating a REST API for the DotNetNuke 6 site using the DNN MVC service infrastructure. However, I do not have a background for authentication, so I donβt even know where to start.
Basically, we want our customers to be able to make GET requests for their portal data, and we want some customers (but not all) to receive simple POST updates to their user data.
I am trying to find information, but the problem is that I am not sure what I am looking for. DNN has different logins and roles, but I'm not sure what and how they affect. I have heard about things like oAuth, but my understanding of this is at a very basic level. I do not know what I need or not, and if and how it applies to DNN. Can someone point me in the right direction?
UPDATE : Based on the answer below about binding it to a module and further research, here's what I did:
I created a module only for this service, and I added two special permissions for it: "APIGET" and "APIPOST". I assigned them to some test roles / test accounts in DNN. I wrote a special authorize attribute, which, given the module identifier, checks if the current user has the necessary permission (through roles or directly). As far as I can tell, the tab identifier in my case does not matter.
It seems to work with both a web browser (based on the DNN account I logged in to) and with a php script that sends an HTTP request with username / password.
Authorize attribute:
using DotNetNuke.Entities.Modules; using DotNetNuke.Entities.Portals; using DotNetNuke.Security; using DotNetNuke.Security.Permissions; using System.Web; public class MyAuthorize : DotNetNuke.Web.Services.AuthorizeAttributeBase { public const string AuthModuleFriendlyName = "MyAuthModule"; public const string GETPermission = "APIGET"; public const string POSTPermission = "APIPOST"; public string Permission { get; set; } protected override bool AuthorizeCore(HttpContextBase context) { ModuleController mc = new ModuleController(); ModuleInfo mi = mc.GetModuleByDefinition(PortalController.GetCurrentPortalSettings().PortalId, AuthModuleFriendlyName); ModulePermissionCollection permCollection = mi.ModulePermissions; return ModulePermissionController.HasModulePermission(permCollection, Permission); } }
Controller: ("mytest" is the endpoint for GET and POST)
public class MyController : DnnController { [ActionName("mytest")] [AcceptVerbs(HttpVerbs.Get)] [DnnAuthorize(AllowAnonymous = true)] [MyAuthorize(Permission = MyAuthorize.GETPermission)] public string myget(string id = "") { return "You have my permission to GET"; } [ActionName("mytest")] [AcceptVerbs(HttpVerbs.Post)] [DnnAuthorize(AllowAnonymous = true)] [MyAuthorize(Permission = MyAuthorize.POSTPermission)] public string mypost(string id = "") { return "You have my permission to POST"; } }
restful-authentication dotnetnuke
MysteriousWhisper
source share