コード例 #1
0
 public GraphApiConnector(IAzureAdSecuredApiConnector azureAdSecuredApiConnector, IOptions <AzureAdOptions> options)
 {
     ValidateOptions(options, azureAdSecuredApiConnector);
     _azureAdSecuredApiConnector = azureAdSecuredApiConnector;
     _graphApiUrl = $"https://graph.windows.net/{options.Value.Tenant}";
     _version     = "api-version=1.6";
 }
コード例 #2
0
        private void ValidateOptions(IOptions <AzureAdOptions> options, IAzureAdSecuredApiConnector azureAdSecuredApiConnector)
        {
            if (azureAdSecuredApiConnector == null)
            {
                throw new Exception("No implementation has been registered for IAzureAdSecuredApiConnector");
            }
            if (options == null)
            {
                throw new Exception("The AzureAdOptions in de config could not be found. Did you register them? IOptions<AzureAdOptions>");
            }
            var validationErrors = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(options?.Value?.Tenant))
            {
                validationErrors.Add("Tenant", "AzureAD authority is not specified in the settings");
            }
            if (validationErrors.Any())
            {
                var errormessage = "";
                foreach (var validationError in validationErrors)
                {
                    errormessage += $"{validationError.Key}, ";
                }
                throw new Exception("The following azureAdSettings are empty: " + errormessage);
            }
        }
コード例 #3
0
 public ExampleController(IAzureAdSecuredApiConnector azureAdSecuredApiConnector, IOptions <AzureAdOptions> azureSettingsAccessor)
 {
     _azureAdSecuredApiConnector = azureAdSecuredApiConnector;
     _azureAdOptions             = azureSettingsAccessor.Value;
 }