public async Task <IActionResult> TwitchOAuth(int?id) { if (id == null) { return(NotFound()); } var stream = await _context.StreamModels.FindAsync(id); if (stream == null) { return(NotFound()); } StreamOAuthDataModel model = new StreamOAuthDataModel(); model.Id = stream.ID.ToString(); string baseurl = _configuration.GetSection("WebServerWebAddress").Value; model.RedirectLinkForTwitch = $"{baseurl}/Stream/TwitchReturnUrlAction"; model.StatusMessage = StatusMessage; return(View(model)); }
public async Task <IActionResult> TwitchOAuth(int id, [Bind("Id,ClientId,Secret")] StreamOAuthDataModel StreamOAuthData) { if (id != Int32.Parse(StreamOAuthData.Id)) { return(NotFound()); } if (ModelState.IsValid && StreamOAuthData.ClientId != "" && StreamOAuthData.Secret != "") { var baseUrl = _configuration.GetSection("WebServerWebAddress").Value; string state = StreamOAuthData.Id + StreamOAuthData.Secret; Stream stream = _context.StreamModels.Where(sm => sm.ID == Int32.Parse(StreamOAuthData.Id)).FirstOrDefault(); if (stream != null) { stream.Secret = StreamOAuthData.Secret; stream.ClientID = StreamOAuthData.ClientId; } await _context.SaveChangesAsync(); return(Redirect($"https://id.twitch.tv/oauth2/authorize?response_type=code&client_id={StreamOAuthData.ClientId}&redirect_uri={baseUrl}/Stream/TwitchReturnUrlAction&scope=channel_editor+user:edit&state={state}")); } StatusMessage = "ClientID und Secret entweder leer oder falsch"; return(View(nameof(TwitchOAuth))); }