private static ClientAuthorizationSettings GetAuthSettingsVersion2(ILeverConfiguration configuration, string client)
        {
            var clientConfiguration = ClientConfigurationHelper.GetConfigurationForClient(configuration, client);

            if (clientConfiguration == null)
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(clientConfiguration.Authentication))
            {
                return(new ClientAuthorizationSettings
                {
                    AuthorizationType = ClientAuthorizationSettings.AuthorizationTypeEnum.None
                });
            }

            var authentications = GetAuthentications(configuration);

            if (authentications == null || !authentications.TryGetValue(clientConfiguration.Authentication, out var authentication))
            {
                throw new FulcrumResourceException($"Client '{client}' refers to authentication '{clientConfiguration.Authentication}', which does not exist");
            }

            return(authentication);
        }
Ejemplo n.º 2
0
        public void MultipleAuthenticationsFail()
        {
            SetupConfigMock(new Dictionary <string, string>
            {
                { "Authorization", "bar" }
            });

            ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);
        }
Ejemplo n.º 3
0
        public void NoAuthentication()
        {
            SetupConfigMock(null);

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientNameNoAuth);

            Assert.IsNotNull(config);
            Assert.IsNull(config.Authentication);
        }
Ejemplo n.º 4
0
        public void NullHeaders()
        {
            SetupConfigMock(null);

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config);
            Assert.IsNull(config.RequestHeaders);
        }
Ejemplo n.º 5
0
        public void EmptyHeaders()
        {
            SetupConfigMock(new Dictionary <string, string>());

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(0, config.RequestHeaders.Count);
        }
Ejemplo n.º 6
0
        public void MultipleClients()
        {
            var configs = ClientConfigurationHelper.GetClientsConfigurations(LeverConfiguration);

            Assert.AreEqual(_clientConfigurations.Count, configs.Count);
            Assert.IsTrue(configs.ContainsKey(ClientName));
            Assert.IsTrue(configs.ContainsKey(ClientName2));
            Assert.IsTrue(configs.ContainsKey(ClientNameNoAuth));
            Assert.IsTrue(configs.ContainsKey(ClientName4));
        }
Ejemplo n.º 7
0
        public void SingleHeader()
        {
            SetupConfigMock(new Dictionary <string, string>
            {
                { "foo", "bar" }
            });

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(1, config.RequestHeaders.Count);
            Assert.IsTrue(config.RequestHeaders.ContainsKey("foo"));
            Assert.AreEqual("bar", config.RequestHeaders["foo"]);
            Assert.AreEqual("auth", config.Authentication);
        }
Ejemplo n.º 8
0
        public void ConfigurationFromJsonFile()
        {
            // https://docs.nexus.link/docs/client-authentication-methods
            LeverConfiguration = new MockLeverConfiguration(JObject.Parse(File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}\\Clients\\client-config.json")));

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, "client-a");

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(2, config.RequestHeaders.Count);
            Assert.IsTrue(config.RequestHeaders.ContainsKey("header-a"));
            Assert.IsTrue(config.RequestHeaders.ContainsValue("value-a"));
            Assert.IsTrue(config.RequestHeaders.ContainsKey("header-b"));
            Assert.IsTrue(config.RequestHeaders.ContainsValue("value-b"));
            Assert.AreEqual("auth", config.Authentication);

            config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, "client-no-auth");
            Assert.IsNotNull(config);
            Assert.IsNull(config.Authentication);
        }
Ejemplo n.º 9
0
        public void ConfigureIdentityServer(IAppBuilder app, string baseUri, string serverName, string logLocation)
        {
            // setup defaults
            var identityProvider = new Rezare.IdentityServer.AspNetIdentity.IdentityProviderHelper();

            try
            {
                var assemblyName = typeof(Scopes).Assembly.FullName;
                var clients      = ClientConfigurationHelper.Get();

                // setup identity server options
                var options = new IdentityServerSetupOptions()
                {
                    IdentityServerName       = serverName,
                    BaseUri                  = baseUri.ToString(),
                    IdentityProvider         = identityProvider,
                    Scopes                   = Scopes.Get(),
                    Clients                  = clients,
                    HostRedirectFinalPage    = true,
                    UpdateDatabaseFromConfig = true,
                    ConnectionStringName     = ConfigurationManager.AppSettings["ConnectionStringName"],
                    EmailSettings            = new ServerSettings()
                    {
                        SendAs     = ConfigurationManager.AppSettings["SmtpSendAs"],
                        Password   = ConfigurationManager.AppSettings["SmtpPassword"],
                        Port       = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]),
                        ServerName = ConfigurationManager.AppSettings["SmtpServer"],
                        UserName   = ConfigurationManager.AppSettings["SmtpUser"],
                        UseSSL     = Convert.ToBoolean(ConfigurationManager.AppSettings["SmtpUseSsl"])
                    }
                };

                options.EmbeddedViewOptions.ContentAssembly     = assemblyName;
                options.InternalClientOptions.Secret            = ConfigurationManager.AppSettings["InternalClientSecret"];
                options.AccountOptions.ForgottenPasswordOptions = new ForgottenPasswordOptions
                {
                    Provide    = true,
                    FindUserBy = FindUserBy.Username,
                    Assembly   = assemblyName
                };

                options.PasswordOptions.RequireNonLetterOrDigit            = false;
                options.PasswordOptions.MinimumLength                      = 8;
                options.AccountOptions.ForgottenPasswordOptions.FindUserBy = FindUserBy.Username;
                options.ProcessUris();

                // setup logging
                app.ConfigureLogging(logLocation);

                // use identity server api
                app.UseIdentityServerApi(new IdentityServerApiSetupOptions()
                {
                    Authority            = options.FullUri,
                    IdentityProvider     = identityProvider,
                    PasswordOptions      = options.PasswordOptions,
                    ConnectionStringName = ConfigurationManager.AppSettings["ConnectionStringName"]
                });

                // use identity server
                app.UseIdentityServer(options);
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }
        }