fix #1367 - provides support for multiple entities in auth policy and makes parameter names more intuitive - backward compatible with entityid

This commit is contained in:
Shaun Walker
2021-05-23 10:29:05 -04:00
parent 6f123c0fff
commit 3f48c1f8fe
7 changed files with 126 additions and 42 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
@ -52,10 +53,15 @@ namespace Oqtane.Services
return apiurl;
}
// add entityid parameter to url for custom authorization policy
public string CreateAuthorizationPolicyUrl(string url, int entityId)
// add authentityid parameters to url for custom authorization policy - args in form of entityname = entityid
public string CreateAuthorizationPolicyUrl(string url, Dictionary<string, int> args)
{
string qs = "entityid=" + entityId.ToString();
string qs = "";
foreach (KeyValuePair<string, int> kvp in args)
{
qs += (qs != "") ? "&" : "";
qs += "auth" + kvp.Key.ToLower() + "id=" + kvp.Value.ToString();
}
if (url.Contains("?"))
{
@ -202,5 +208,20 @@ namespace Oqtane.Services
{
return CreateApiUrl(serviceName, alias, ControllerRoutes.Default);
}
[Obsolete("This method is obsolete. Use CreateAuthorizationPolicyUrl(string url, Dictionary<string, int> args) instead - in conjunction with _authEntityId in Server Controller.", false)]
public string CreateAuthorizationPolicyUrl(string url, int entityId)
{
string qs = "entityid=" + entityId.ToString();
if (url.Contains("?"))
{
return url + "&" + qs;
}
else
{
return url + "?" + qs;
}
}
}
}