Beispiel #1
0
        private void OnSaveButtonClick(object sender, RoutedEventArgs e)
        {
            lock (this.itemLock)
            {
                UpdateValidity();

                if (this.EventsList.Any(item => item.IsInvalid))
                {
                    MainContent.Instance.ShowSimpleDialog("Errors in events", "Please make there are no invalid values in events.");
                }
                else
                {
                    // Legacy events
                    var twitchOptions = new TwitchOptions()
                    {
                        IsRedemptionInChat  = this.IsRedemptionInChatBox.IsChecked ?? false,
                        IsRedemptionTagUser = this.IsTagUserBox.IsChecked ?? false,
                        RedemptionTagUser   = this.UserNameTextBox.Text,
                        IsAutoShoutOutHost  = this.IsAutoShoutOutBox.IsChecked ?? false,
                        GreetingMessage     = this.GreetingMessage.Text ?? "Hai hai, I'm connected and ready to go!"
                    };
                    ConfigManager.SaveTwitchOptionsConfigs(twitchOptions);

                    // Custom events
                    ConfigManager.SaveEvents(new EventsModel()
                    {
                        Events = this.EventsList.ConvertAll(item => item.ToModel())
                    });

                    MainContent.Instance.ShowSimpleDialog("Events saved!", "");
                }
            }
        }
Beispiel #2
0
        public TwitchService(HttpClient client, IOptions <TwitchOptions> options)
        {
            _client        = client;
            _twitchOptions = options.Value;

            _client.DefaultRequestHeaders.Add("Accept", "application/vnd.twitchtv.v5+json");
            _client.DefaultRequestHeaders.Add("Client-ID", _twitchOptions.ClientId);
        }
Beispiel #3
0
 /// <summary>
 /// [DEPRECATED] Saves the Twitch options and shows a dialog if successful.
 /// </summary>
 public void SetupTwitchOptions(TwitchOptions options)
 {
     this.twitchOptions = options;
     if (ConfigManager.SaveTwitchOptionsConfigs(this.twitchOptions))
     {
         Utilities.ShowMessage("Twitch options saved!");
     }
 }
 public TwitchService(IOptionsMonitor <TwitchOptions> twitchOptions, IOptionsMonitor <TableStorageOptions> tableStorageOptions, IHttpContextAccessor httpContextAccessor, ITwitchHttpClient twitchHttpClient, IStorageService storageService, ILogger <TwitchService> logger)
 {
     _twitchOptions       = twitchOptions.CurrentValue;
     _tableStorageOptions = tableStorageOptions.CurrentValue;
     _httpContextAccessor = httpContextAccessor;
     _twitchHttpClient    = twitchHttpClient;
     _storageService      = storageService;
     _logger = logger;
 }
Beispiel #5
0
        public TwitchEBSService(IHttpClientFactory httpClientFactory, IOptions <TwitchOptions> options, ILogger <TwitchEBSService> logger)
        {
            _options = options.Value;
            _twitchExtensionClient             = httpClientFactory.CreateClient("twitchExt");
            _twitchExtensionClient.BaseAddress = new Uri("https://api.twitch.tv/extensions/");
            _twitchExtensionClient.DefaultRequestHeaders.Add("Client-Id", _options.ClientId);

            var securityKey = new SymmetricSecurityKey(Convert.FromBase64String(_options.ExtensionSecret));

            _jwtSigningCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
        }
Beispiel #6
0
        private void OnSaveButtonClick(object sender, RoutedEventArgs e)
        {
            var twitchOptions = new TwitchOptions()
            {
                IsRedemptionInChat  = this.IsRedemptionInChat,
                IsRedemptionTagUser = this.IsTagUserBox.IsChecked ?? false,
                RedemptionTagUser   = this.UserNameTextBox.Text,
                IsAutoShoutOutHost  = this.IsAutoShoutOutBox.IsChecked ?? false
            };

            QTCore.Instance.SetupTwitchOptions(twitchOptions);
        }
Beispiel #7
0
 public LifetimeMonitoringHostedService(ILogger <LifetimeMonitoringHostedService> logger, IOptions <DiscordOptions> discordOptions, IOptions <TwitchOptions> twitchOptions)
 {
     _logger         = logger;
     _discordOptions = discordOptions.Value;
     _twitchOptions  = twitchOptions.Value;
 }
Beispiel #8
0
 public void LoadConfigs()
 {
     this.mainConfig    = ConfigManager.ReadConfig();
     this.twitchOptions = new TwitchOptions(ConfigManager.ReadTwitchOptionsConfigs());
 }
Beispiel #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // Ceci est un commentaire
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddRazorPages();
            services.AddHttpClient();
            services.Configure <XApiOptions>(Configuration.GetSection("xapi"));
            services.Configure <SteamApiOptions>(Configuration.GetSection("steam"));
            services.Configure <TwitchOptions>(Configuration.GetSection("twitch"));
            services.Configure <ConfigurationTokenOptions>(Configuration.GetSection("config"));
            services.AddSingleton <XApiService>();
            services.AddSingleton <SteamApiService>();
            services.AddSingleton <ConfigurationTokenService>();
            services.AddSingleton <ConfigurationService>();
            services.AddSingleton <TwitchEBSService>();
            services.AddMemoryCache();

            services.AddApplicationInsightsTelemetry();
            services.AddTransient <ITelemetryInitializer, TwitchUserTelemetryInitializer>();

            // For development mode
            if (Configuration.GetValue <bool>("config:IgnoreAuthentication", false))
            {
                // Disable authentication and authorization.
                services.AddSingleton <IPolicyEvaluator, DisableAuthenticationPolicyEvaluator>();
            }
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                TwitchOptions twitchOptions = new TwitchOptions();
                Configuration.GetSection("twitch").Bind(twitchOptions);
                var signingKey = new SymmetricSecurityKey(Convert.FromBase64String(twitchOptions.ExtensionSecret));
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey = signingKey,
                    ValidateAudience = false,   // No audience on extension tokens
                    ValidateIssuer   = false,   // No issuer either
                };

                options.Events = new JwtBearerEvents
                {
                    OnTokenValidated = (validationContext) =>
                    {
                        var token = validationContext.SecurityToken as JwtSecurityToken;

                        options.TokenValidationParameters.NameClaimTypeRetriever = (token, _) =>
                        {
                            var jwtToken = token as JwtSecurityToken;
                            if (jwtToken.Payload.ContainsKey("user_id"))
                            {
                                return("user_id");
                            }
                            else
                            {
                                return("opaque_user_id");
                            }
                        };

                        return(Task.CompletedTask);
                    }
                };
            });
        }
Beispiel #10
0
 public static bool SaveTwitchOptionsConfigs(TwitchOptions options)
 {
     return(SaveConfig <TwitchOptionsModel>("TwitchOptionsConfigs.json", options.GetModel()));
 }