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 IAppBuilder UseAppServiceAuthentication(this IAppBuilder appBuilder, HttpConfiguration config, AppServiceAuthenticationMode appServiceAuthMode, AuthenticationMode mode = AuthenticationMode.Active)
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException("appBuilder");
            }

            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            MobileAppAuthenticationOptions serviceOptions = GetMobileAppAuthenticationOptions(config, mode);
            IMobileAppTokenHandler tokenHandler = config.GetMobileAppTokenHandler();
            appBuilder.UseAppServiceAuthentication(config, appServiceAuthMode, serviceOptions, tokenHandler);

            return appBuilder;
        }