// JwtBearer Authorization, Query String Parameters public ApiSourceOptions(string configUrlVar, string authVar, string clientIdVar, string clientSecretVar, string clientScopeVar, Dictionary <string, string> qParams, bool optional) { _optional = optional; _queryParams = qParams; AuthType = "JwtBearer"; JWTBearerOptions = new JWTBearerOptions( Environment.GetEnvironmentVariable(authVar), Environment.GetEnvironmentVariable(clientIdVar), Environment.GetEnvironmentVariable(clientSecretVar), Environment.GetEnvironmentVariable(clientScopeVar) ); ValidateBearerConfig(); SetDefaults(); SetConfigUrlFromEnvVar(configUrlVar); SetQueryParameters(); }
// JwtBearer Authorization, Route Parameters public ApiSourceOptions(string configUrlVar, string authVar, string clientIdVar, string clientSecretVar, string clientScopeVar, string[] rParams, bool optional) { _optional = optional; JWTBearerOptions = new JWTBearerOptions( Environment.GetEnvironmentVariable(authVar), Environment.GetEnvironmentVariable(clientIdVar), Environment.GetEnvironmentVariable(clientSecretVar), Environment.GetEnvironmentVariable(clientScopeVar) ); ValidateBearerConfig(); AuthType = "JwtBearer"; _routeParams = rParams; SetDefaults(); SetConfigUrlFromEnvVar(configUrlVar); SetRouteParametersWithDefault(); }
/// <summary> /// Accepts Configuration as parameter. Used to override default api client settings /// </summary> /// <param name="config"></param> /// <param name="optional"></param> public ApiSourceOptions(IConfiguration config, bool optional) { //Bearer Auth //TODO Query Params IConfigurationSection apiSection = config.GetSection("ConfigOptions:ApiSource"); if (!apiSection.Exists()) { throw new Exception("ApiSource section not found in configuration"); } ConfigUrlKey = apiSection["ConfigUrlKey"]; ConfigUrl = config[ConfigUrlKey]; AuthType = apiSection["AuthType"]; // SET and validate Auth Secret for Cert and Api Key if (AuthType == "Certificate" || AuthType == "ApiKey") { AuthSecret = apiSection["AuthSecret"]; if (string.IsNullOrEmpty(AuthSecret)) { throw new Exception($"Authentication secret not found in configuration setting - 'ConfigOptions:ApiSource:AuthSecret'"); } } // Set and validate IDP options for JWTBearer if (AuthType == "JwtBearer") { { JWTBearerOptions = new JWTBearerOptions( apiSection["Authority"], apiSection["ClientId"], apiSection["ClientSecret"], apiSection["ClientScope"] ); ValidateBearerConfig(); } } //Add defaults for any required values that were not supplied SetDefaults(); //Set Full Configuration API URI including action and Parmater ConfigUrl = config[ConfigUrlKey]; if (string.IsNullOrEmpty(ConfigUrl)) { throw new Exception($"Configuration setting not found: '{ConfigUrlKey}'"); } //Set QueryParameter member from configuration section first before checking if the default Route Parameter should be added // IConfigurationSection qParamSection = config.GetSection("ConfigOptions:ApiSource:QueryParams"); // if (qParamSection != null) _queryParams = config.GetSection("ConfigOptions:ApiSource:QueryParams")?.GetChildren().ToDictionary(x => x.Key, x => x.Value); // var children = qParamSection?.GetChildren(); // IF the query parameters section has values, convert to dictionary for SetQueryParameters Method //if (_queryParams != null) //{ // // if query paramaters have been supplied, add them as query string parameters // _queryParams = new Dictionary<string, string>(); // foreach (var child in children) // { // _queryParams.Add(child.Key, child.Value); // } SetQueryParameters(); //} //Set RouteParameter member from configuration section IConfigurationSection rParamSection = config.GetSection("ConfigOptions:ApiSource:RouteParams"); //if (rParamSection != null) //{ _routeParams = rParamSection?.Get <string[]>(); //} // Set Route Parameters if present, or default route parameter if needed SetRouteParametersWithDefault(); }