Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Nullinside.Api.TwitchBot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api", "nullinsid
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api.TwitchBot.Tests", "Nullinside.Api.TwitchBot.Tests\Nullinside.Api.TwitchBot.Tests.csproj", "{2CBAC21E-256B-493E-9461-7C779B137926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api.Tests", "nullinside-api\src\Nullinside.Api.Tests\Nullinside.Api.Tests.csproj", "{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -52,5 +54,9 @@ Global
{2CBAC21E-256B-493E-9461-7C779B137926}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CBAC21E-256B-493E-9461-7C779B137926}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CBAC21E-256B-493E-9461-7C779B137926}.Release|Any CPU.Build.0 = Release|Any CPU
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
18 changes: 12 additions & 6 deletions src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nullinside.Api.Common.Twitch;
using Nullinside.Api.Model;
using Nullinside.Api.Model.Shared;
using Nullinside.Api.Shared.Support;

namespace Nullinside.Api.TwitchBot.Controllers;

Expand Down Expand Up @@ -56,23 +57,28 @@ public LoginController(INullinsideContext dbContext, IConfiguration configuratio
/// </returns>
[AllowAnonymous]
[HttpGet]
[Route("twitch-login")]
public async Task<IActionResult> TwitchLogin([FromQuery] string code, [FromServices] ITwitchApiProxy api, CancellationToken token) {
string? siteUrl = _configuration.GetValue<string>("Api:SiteUrl");
if (null == await api.CreateAccessToken(code, token)) {
return Redirect($"{siteUrl}/twitch-bot/login?error=3");
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.TwitchErrorWithToken}");
}

string? email = await api.GetUserEmail(token);
if (string.IsNullOrWhiteSpace(email)) {
return Redirect($"{siteUrl}/twitch-bot/login?error=4");
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.TwitchAccountHasNoEmail}");
}

string? bearerToken = await UserHelpers.GetTokenAndSaveToDatabase(_dbContext, email, token);
(string? id, string? username) user = await api.GetUser(token);
if (string.IsNullOrWhiteSpace(user.username) || string.IsNullOrWhiteSpace(user.id)) {
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.InternalError}");
}

string? bearerToken = await UserHelpers.GetTokenAndSaveToDatabase(_dbContext, email, token, api.OAuth?.AccessToken,
api.OAuth?.RefreshToken, api.OAuth?.ExpiresUtc, user.username, user.id);
if (string.IsNullOrWhiteSpace(bearerToken)) {
return Redirect($"{siteUrl}/twitch-bot/login?error=2");
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.InternalError}");
}

return Redirect($"{siteUrl}/twitch-bot/login?token={bearerToken}");
return Redirect($"{siteUrl}/twitch-bot/config?token={bearerToken}");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Nullinside.Api.TwitchBot_HostAddress = http://localhost:5086
@Nullinside.Api.TwitchBot_HostAddress = http://localhost:5941

GET {{Nullinside.Api.TwitchBot_HostAddress}}/weatherforecast/
Accept: application/json
Expand Down
3 changes: 3 additions & 0 deletions src/Nullinside.Api.TwitchBot/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"Api": {
"SiteUrl": "http://localhost:4200"
}
}
5 changes: 4 additions & 1 deletion src/Nullinside.Api.TwitchBot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Api": {
"SiteUrl": "https://nullinside.com"
}
}
Loading