Exemple #1
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

#if DEBUG
            config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
#endif

            new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config);

            config.Services.Add(typeof(IExceptionLogger), new AiExceptionLogger());

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new MobileServiceInitializer());

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
        }
Exemple #2
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            new MobileAppConfiguration()
                .UseDefaultConfiguration()
                .ApplyTo(config);

            app.UseWebApi(config);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 
            config.EnableSystemDiagnosticsTracing();

            new MobileAppConfiguration()
                .ApplyTo(config);

            // To prevent Entity Framework from modifying your database schema, use a null database initializer
            // Database.SetInitializer<LoanApp_MerchantContext>(null);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                // This middleware is intended to be used locally for debugging. By default, HostName will
                // only have a value when running in an App Service application.
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    SigningKey = "GfYVqdtZUJQfghRiaonAeRQRDjytRi47",
                    ValidAudiences = new[] { "http://localhost" },
                    ValidIssuers = new[] { "http://localhost" },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }
            app.UseWebApi(config);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 
            //config.EnableSystemDiagnosticsTracing();

            new MobileAppConfiguration()
                .UseDefaultConfiguration()
                .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new CreateDatabaseIfNotExists<net_perfContext>());

            // To prevent Entity Framework from modifying your database schema, use a null database initializer
            // Database.SetInitializer<net_perfContext>(null);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                // This middleware is intended to be used locally for debugging. By default, HostName will
                // only have a value when running in an App Service application.
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }
            app.UseWebApi(config);
        }
        public static IAppBuilder UseAppServiceAuthentication(this IAppBuilder appBuilder, HttpConfiguration config, AppServiceAuthenticationMode appServiceAuthMode, MobileAppAuthenticationOptions options, IMobileAppTokenHandler tokenHandler)
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException("appBuilder");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
            bool runningInAzure = !string.IsNullOrEmpty(settings.HostName);

            if ((appServiceAuthMode == AppServiceAuthenticationMode.LocalOnly && !runningInAzure)
                            || appServiceAuthMode == AppServiceAuthenticationMode.Always)
            {
                appBuilder.Use(typeof(MobileAppAuthenticationMiddleware), new object[]
                {
                    appBuilder,
                    options,
                    tokenHandler
                });
            }
            return appBuilder;
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute("XamarinAuthProvider", ".auth/login/xamarin", new { controller = "XamarinAuth" });

            //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
            config.EnableSystemDiagnosticsTracing();

                new MobileAppConfiguration()
                .UseDefaultConfiguration()
                .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new XamarinEvolveContextInitializer());

            // To prevent Entity Framework from modifying your database schema, use a null database initializer
            // Database.SetInitializer(null);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            // This middleware is intended to be used locally for debugging. By default, HostName will
            // only have a value when running in an App Service application.
            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new Microsoft.Azure.Mobile.Server.Authentication.AppServiceAuthenticationOptions
                {

                });
            }

            app.UseWebApi(config);
        }
        public async Task <ActionResult> Index(Models.SendNotificationsModel model)
        {
            //get notification hub information
            // Get the settings for the server project.

            System.Web.Http.HttpConfiguration config =
                System.Web.Http.GlobalConfiguration.Configuration;
            MobileAppSettingsDictionary settings =
                config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            // Get the Notification Hubs credentials for the Mobile App.
            string notificationHubName       = settings.NotificationHubName;
            string notificationHubConnection = settings
                                               .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;

            // Create a new Notification Hub client.
            NotificationHubClient hub = NotificationHubClient
                                        .CreateClientFromConnectionString(notificationHubConnection, notificationHubName);

            // Sending the message so that all template registrations that contain "messageParam"
            // will receive the notifications. This includes APNS, GCM, WNS, and MPNS template registrations.
            Dictionary <string, string> templateParams = new Dictionary <string, string>();

            templateParams["title"]   = model.Title;
            templateParams["message"] = model.Message;

            try
            {
                NotificationOutcome result = null;

                // Send the push notification and log the results.
                if (model.Tags != null && model.Tags.Count > 0)
                {
                    result = await hub.SendTemplateNotificationAsync(templateParams, String.Join(" || ", model.Tags));
                }
                else
                {
                    result = await hub.SendTemplateNotificationAsync(templateParams);
                }

                // Write the success result to the logs.
                config.Services.GetTraceWriter().Info(result.State.ToString());
            }
            catch (System.Exception ex)
            {
                // Write the failure result to the logs.
                config.Services.GetTraceWriter()
                .Error(ex.Message, null, "Push.SendAsync Error");
                throw;
            }

            //redirct to confirm
            return(View("Confirm"));
        }
        public void GetMobileAppSettingsProvider_ReturnsDefaultInstance()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            IMobileAppSettingsProvider actual = config.GetMobileAppSettingsProvider();

            // Assert
            Assert.NotNull(actual);
            Assert.IsType<MobileAppSettingsProvider>(actual);
        }
        /// <summary>
        /// Gets the <see cref="MobileAppAuthenticationOptions" /> that will be used by the <see cref="MobileAppAuthenticationHandler"/>./>
        /// </summary>
        /// <returns>The <see cref="MobileAppAuthenticationOptions" /> to use.</returns>
        private static MobileAppAuthenticationOptions GetMobileAppAuthenticationOptions(HttpConfiguration config, AuthenticationMode mode)
        {
            IMobileAppSettingsProvider settingsProvider = config.GetMobileAppSettingsProvider();
            MobileAppSettingsDictionary settings = settingsProvider.GetMobileAppSettings();

            MobileAppAuthenticationOptions serviceOptions = new MobileAppAuthenticationOptions
            {
                AuthenticationMode = mode,
                SigningKey = settings.SigningKey,
            };

            return serviceOptions;
        }
        public void SetMobileAppSettingsProvider_Roundtrips()
        {
            // Arrange
            MobileAppSettingsProvider provider = new MobileAppSettingsProvider();
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.SetMobileAppSettingsProvider(provider);
            IMobileAppSettingsProvider actual = config.GetMobileAppSettingsProvider();

            // Assert
            Assert.Same(provider, actual);
        }
        private TestServer CreateTestServer(bool skipVersionCheck = false)
        {
            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

            new MobileAppConfiguration()
                .AddTables()
                .ApplyTo(config);

            IMobileAppSettingsProvider settingsProvider = config.GetMobileAppSettingsProvider();
            var settings = settingsProvider.GetMobileAppSettings();
            settings.SkipVersionCheck = skipVersionCheck;

            return TestServer.Create(appBuilder =>
            {
                appBuilder.UseWebApi(config);
            });
        }
Exemple #12
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            new MobileAppConfiguration()
                .AddTables(
                    new MobileAppTableConfiguration()
                        .MapTableControllers()
                        .AddEntityFramework())
                .MapApiControllers()
                .ApplyTo(config);

            // To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            //Database.SetInitializer(new LinquaInitializer());

            Database.SetInitializer(new MigrateDatabaseToLatestVersion<LinquaContext, Configuration>());
            //var migrator = new DbMigrator(new Configuration());
            //migrator.Update("AddIndexOnTextColumn");

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            // See: http://www.systemsabuse.com/2015/12/04/local-debugging-with-user-authentication-of-an-azure-mobile-app-service/
            if (string.IsNullOrEmpty(settings.HostName))
            {
                // This middleware is intended to be used locally for debugging. By default, HostName will
                // only have a value when running in an App Service application.
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }
            app.UseWebApi(config);
        }
            private AppServiceAuthenticationOptions GetMobileAppAuthOptions(HttpConfiguration config)
            {
                MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

                return new AppServiceAuthenticationOptions
                {
                    SigningKey = this.SigningKey,
                    ValidAudiences = this.ValidAudiences,
                    ValidIssuers = this.ValidIssuers,
                    TokenHandler = config.GetAppServiceTokenHandler()
                };
            }
        public void SetMobileAppSettingsProvider_ReturnsDefault_IfSetToNull()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.SetMobileAppSettingsProvider(null);
            IMobileAppSettingsProvider actual = config.GetMobileAppSettingsProvider();

            // Assert
            Assert.NotNull(actual);
            Assert.IsType<MobileAppSettingsProvider>(actual);
        }
            private TestServer CreateTestServer(HttpConfiguration config)
            {
                config.MapHttpAttributeRoutes();

                new MobileAppConfiguration()
                    .MapApiControllers()
                    .AddTables(
                        new MobileAppTableConfiguration()
                        .MapTableControllers())
                    .ApplyTo(config);

                // setup test authorization config values
                IMobileAppSettingsProvider settingsProvider = config.GetMobileAppSettingsProvider();
                var settings = settingsProvider.GetMobileAppSettings();
                settings.SigningKey = SigningKeyAlpha;

                return TestServer.Create((appBuilder) =>
                {
                    appBuilder.UseAppServiceAuthentication(config, AppServiceAuthenticationMode.LocalOnly);
                    appBuilder.UseWebApi(config);
                });
            }
            private TestServer CreateTestServer(HttpConfiguration config, bool skipTokenSignatureValidation)
            {
                config.MapHttpAttributeRoutes();

                new MobileAppConfiguration()
                    .MapApiControllers()
                    .AddTables(
                        new MobileAppTableConfiguration()
                        .MapTableControllers())
                    .ApplyTo(config);

                // setup test authorization config values
                IMobileAppSettingsProvider settingsProvider = config.GetMobileAppSettingsProvider();
                var settings = settingsProvider.GetMobileAppSettings();
                settings.SigningKey = "signing_key";

                return TestServer.Create((appBuilder) =>
                {
                    MobileAppAuthenticationOptions options = new MobileAppAuthenticationOptions()
                    {
                        SigningKey = settings.SigningKey,
                        SkipTokenSignatureValidation = skipTokenSignatureValidation
                    };

                    appBuilder.UseMobileAppAuthentication(options, config.GetMobileAppTokenHandler());
                    appBuilder.UseWebApi(config);
                });
            }