Пример #1
0
        public APITemplateAuthenticationSettings ConvertYAMLFileToAuthenticationSettings(string yamlFileLocation)
        {
            APITemplateAuthenticationSettings authenticationSettings = new APITemplateAuthenticationSettings();
            // Setup the input
            StreamReader streamReader = new StreamReader(yamlFileLocation);
            // Load the stream
            YamlStream yaml = new YamlStream();

            yaml.Load(streamReader);
            // Examine the stream
            YamlMappingNode mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            foreach (var entry in mapping.Children)
            {
                string key = ((YamlScalarNode)entry.Key).Value;
                if (key == "authenticationSettings")
                {
                    YamlMappingNode node = (YamlMappingNode)entry.Value;
                    // find the the values from the YAML and set the corresponding properties on the version set object
                    authenticationSettings.subscriptionKeyRequired = (string)node.Children.First(child => (string)child.Key == "subscriptionKeyRequired").Value == "true" ? true : false;
                    authenticationSettings.oAuth2 = new APITemplateOAuth2();
                    authenticationSettings.openid = new APITemplateOpenID();
                    foreach (var child in node.Children)
                    {
                        string childKey = ((YamlScalarNode)child.Key).Value;
                        if (childKey == "oAuth2")
                        {
                            YamlMappingNode childNode = (YamlMappingNode)child.Value;
                            // find the the values from the YAML and set the corresponding properties on the version set object
                            authenticationSettings.oAuth2.authorizationServerId = (string)childNode.Children.First(c => (string)c.Key == "authorizationServerId").Value;
                            authenticationSettings.oAuth2.scope = (string)childNode.Children.First(c => (string)c.Key == "scope").Value;
                        }
                        else if (childKey == "openid")
                        {
                            YamlMappingNode childNode = (YamlMappingNode)child.Value;
                            // find the the values from the YAML and set the corresponding properties on the version set object
                            authenticationSettings.openid.openidProviderId = (string)childNode.Children.First(c => (string)c.Key == "openidProviderId").Value;
                            List <string> methods = new List <string>();
                            foreach (var subChild in childNode.Children)
                            {
                                string subkey = ((YamlScalarNode)subChild.Key).Value;
                                if (subkey == "bearerTokenSendingMethods")
                                {
                                    YamlSequenceNode subChildNode = (YamlSequenceNode)subChild.Value;
                                    foreach (YamlScalarNode deepChild in subChildNode.Children)
                                    {
                                        methods.Add(deepChild.Value);
                                    }
                                }
                            }
                            authenticationSettings.openid.bearerTokenSendingMethods = methods.ToArray();
                        }
                    }
                }
            }
            return(authenticationSettings);
        }
 public Exception AttemptAuthenticationSettingsConversion(CLICreatorArguments cliArguments)
 {
     try
     {
         YAMLReader yamlReader = new YAMLReader();
         APITemplateAuthenticationSettings authenticationSettings = yamlReader.ConvertYAMLFileToAuthenticationSettings(cliArguments.authenticationSettingsFile);
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }