Beispiel #1
0
        private async void btnAuthenticate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtApplicationID.Text.Length > 20 &&
                    txtSharedSecret.Text.Length > 20)
                {
                    btnAuthenticate.Text = "Authenticating...";
                    var appAuthInfo = new AppAuthInfo
                    {
                        ApplicationId = txtApplicationID.Text,
                        SharedSecret  = txtSharedSecret.Text
                    };
                    if (txtEmail.Text.Contains("@") &&
                        txtEmail.Text.Contains(".") &&
                        txtPassword.Text.Length > 5)
                    {
                        await AppAuthenticator.InitializeAsync(appAuthInfo);

                        btnAuthenticate.Text = "Loading Scopes...";
                        panelAPI.Visible     = true;
                        panelTenant.Visible  = true;
                        var userAuthInfo = new UserAuthInfo {
                            EmailAddress = txtEmail.Text, Password = txtPassword.Text
                        };
                        _userInfo = await UserAuthenticator.AuthenticateAsync(userAuthInfo, AuthenticationScope.Tenant);

                        panelTenant.Visible = true;
                        _userInfo.AuthorizedScopes.Insert(0, new Scope {
                            Id = -1, Name = "[Select Tenant]"
                        });
                        cbTenant.DataSource = _userInfo.AuthorizedScopes;

                        btnAuthenticate.Text = "Renew Authentication";
                    }
                    else
                    {
                        btnAuthenticate.Text = "Authenticate";
                        LogError(new Exception("Not enough User data entered for User Scope Authentication"));
                    }
                }
                else
                {
                    LogError(new Exception("Not enough Application data entered for Authentication"));
                }
            }
            catch (ApiException exc)
            {
                LogError(exc);
                btnAuthenticate.Text = "Authenticate";
            }
        }
Beispiel #2
0
        public async Task AsyncTest()
        {
            var baseAppAuthUrl = "http://home.mozu-ci.volusion.com/";
            var appId          = "5d76bb2a852d4741939fa27d00d98a40";
            var sharedSecret   = "348f780339b749b58d3fa27d00d98a40";

            var appAuthInfo = new AppAuthInfo
            {
                ApplicationId = appId,
                SharedSecret  = sharedSecret
            };

            MozuConfig.BaseAppAuthUrl = baseAppAuthUrl;
            await AppAuthenticator.InitializeAsync(appAuthInfo);

            Assert.IsNotNull(AppAuthenticator.Instance);
            Assert.IsNotNull(AppAuthenticator.Instance.AppAuthTicket);
            Assert.IsNotNull(AppAuthenticator.Instance.AppAuthTicket.AccessToken);

            //var tenantResource = new TenantResource();
            //var tenant = await tenantResource.GetTenantAsync(9539);
            //Assert.IsNotNull(tenant);
            //Assert.AreEqual(tenant.Id, 9539);
        }
        private void InitDependencyResolvers()
        {
            var appName     = ConfigurationManager.AppSettings["AppName"];
            var configPath  = ConfigurationManager.AppSettings["ConfigPath"];
            var environment = ConfigurationManager.AppSettings["Environment"];

            if (!string.IsNullOrEmpty(appName) && !string.IsNullOrEmpty(configPath) &&
                !String.IsNullOrEmpty(environment))
            {
                var appParams = new List <NamedParameter>
                {
                    new NamedParameter("configPath", configPath),
                    new NamedParameter("appName", appName),
                    new NamedParameter("environment", environment)
                };

                _containerBuilder.RegisterType <AppSetting>().As <IAppSetting>().SingleInstance().WithParameters(appParams);
            }
            else
            {
                _containerBuilder.RegisterType <AppSetting>().As <IAppSetting>().SingleInstance();
            }
            _containerBuilder.RegisterType <Log4NetServiceFactory>().As <ILoggingServiceFactory>().SingleInstance();
            if (ConfigurationManager.AppSettings.AllKeys.Contains("UseGenericEventService") &&
                bool.Parse(ConfigurationManager.AppSettings["UseGenericEventService"]))
            {
                _containerBuilder.RegisterType <Events.GenericEventService>().As <IEventService>();
            }
            else
            {
                _containerBuilder.RegisterType <Events.EventService>().As <IEventService>();
            }

            _containerBuilder.RegisterType <Events.EventServiceFactory>().As <IEventServiceFactory>();

            _containerBuilder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(t => t.Name.EndsWith("Handler"))
            .AsImplementedInterfaces();

            _containerBuilder.RegisterType <EntitySchemaHandler>().As <IEntitySchemaHandler>();
            _containerBuilder.RegisterType <ReturnEventProcessor>().Keyed <IEventProcessor>(EventCategory.Return);
            _containerBuilder.RegisterType <ProductEventProcessor>().Keyed <IEventProcessor>(EventCategory.Product);
            _containerBuilder.RegisterType <OrderEventProcessor>().Keyed <IEventProcessor>(EventCategory.Order);
            _containerBuilder.RegisterType <ApplicationEventProcessor>().Keyed <IEventProcessor>(EventCategory.Application);
            _containerBuilder.RegisterType <CustomerAccountEventProcessor>().Keyed <IEventProcessor>(EventCategory.CustomerAccount);
            _containerBuilder.RegisterType <DiscountEventProcessor>().Keyed <IEventProcessor>(EventCategory.Discount);
            _containerBuilder.RegisterType <CustomerSegmentEventProcessor>().Keyed <IEventProcessor>(EventCategory.CustomerSegment);
            _containerBuilder.RegisterType <TenantEventProcessor>().Keyed <IEventProcessor>(EventCategory.Tenant);
            _containerBuilder.RegisterType <EmailEventProcessor>().Keyed <IEventProcessor>(EventCategory.Email);


            InitializeContainer(_containerBuilder);

            Container = _containerBuilder.Build();

            LogManager.LoggingService = Container.Resolve <ILoggingServiceFactory>().GetLoggingService();
            var appSetting = Container.Resolve <IAppSetting>();

            if (!string.IsNullOrEmpty(appSetting.ApplicationId) && !string.IsNullOrEmpty(appSetting.SharedSecret))
            {
                if (!string.IsNullOrEmpty(appSetting.BaseUrl))
                {
                    MozuConfig.BaseAppAuthUrl = appSetting.BaseUrl;
                }

                if (!string.IsNullOrEmpty(appSetting.BasePCIUrl))
                {
                    MozuConfig.BasePciUrl = appSetting.BasePCIUrl;
                }

                var appAuthenticator = AppAuthenticator.InitializeAsync(new AppAuthInfo {
                    ApplicationId = appSetting.ApplicationId, SharedSecret = appSetting.SharedSecret
                }).Result;
            }


            PostInitialize();
        }