Merge pull request #1387 from sbwalker/dev

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:25:17 -04:00
committed by GitHub
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;
@ -54,10 +55,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("?"))
{
@ -204,5 +210,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;
}
}
}
}