Skip to content

System Parameters

Adrian Ehrsam edited this page Oct 25, 2022 · 2 revisions

There are so called System Parameters, which are parameters defined in any Stored Procedure which should be resolved by the Webserver and not by the Consumer of the API. Built-in are the following System Parameters:

  • ADLogin & NTLogin: The Username in the HttpContext
  • IPAddress: The IP Adress of the User
  • UserAgent: The UserAgent of the Browser

If you want to configure these on your own, you can do something like this:

services.AddGenericBackend()
//...
.AddSystemParameters(prms =>
    {
        prms.Clear(); // clean existing parameters
        prms.AddSystemParameter("UserName", c => c.User?.Identity?.Name); // add your own, beeing based on HttpContext
        prms.AddSystemParameter("UserClaimsJson", c => System.Text.Json.JsonSerializer.Serialize(GetClaims(c.User))); 
        prms.AddSystemParameter("SchemaName.ProcecureName.ParameterNameInThere", c => "I am a webserver"); // used for a single proc only
    });

Dictionary<string, object> GetClaims(ClaimsPrincipal? user) => user?.Claims?.GroupBy(c => c.Type).ToDictionary(c => c.Key, c =>
        {
            var asAr = c.Select(s => s.Value).ToArray();
            return (asAr.Length == 1) ? (object)asAr[0] : (object)asAr;
        });

Then, all procedures with a Parameter named UserName or UserClaimsJson will get the value as provided by your code. These cannot be overwritten from a HTTP Request

Clone this wiki locally