Skip to content

Commit ff00e7e

Browse files
Merge pull request #44 from nullinside-development-group/feature/MoveLoginBackend
Removing login for twitch bot
2 parents 2f6be32 + 878648f commit ff00e7e

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/Nullinside.Api.TwitchBot.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api", "nullinsid
2222
EndProject
2323
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api.TwitchBot.Tests", "Nullinside.Api.TwitchBot.Tests\Nullinside.Api.TwitchBot.Tests.csproj", "{2CBAC21E-256B-493E-9461-7C779B137926}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullinside.Api.Tests", "nullinside-api\src\Nullinside.Api.Tests\Nullinside.Api.Tests.csproj", "{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -52,5 +54,9 @@ Global
5254
{2CBAC21E-256B-493E-9461-7C779B137926}.Debug|Any CPU.Build.0 = Debug|Any CPU
5355
{2CBAC21E-256B-493E-9461-7C779B137926}.Release|Any CPU.ActiveCfg = Release|Any CPU
5456
{2CBAC21E-256B-493E-9461-7C779B137926}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{BAE9E7D6-760A-4E39-BEE9-520F90F3D37C}.Release|Any CPU.Build.0 = Release|Any CPU
5561
EndGlobalSection
5662
EndGlobal

src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Nullinside.Api.Common.Twitch;
77
using Nullinside.Api.Model;
88
using Nullinside.Api.Model.Shared;
9+
using Nullinside.Api.Shared.Support;
910

1011
namespace Nullinside.Api.TwitchBot.Controllers;
1112

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

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

71-
string? bearerToken = await UserHelpers.GetTokenAndSaveToDatabase(_dbContext, email, token);
71+
(string? id, string? username) user = await api.GetUser(token);
72+
if (string.IsNullOrWhiteSpace(user.username) || string.IsNullOrWhiteSpace(user.id)) {
73+
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.InternalError}");
74+
}
75+
76+
string? bearerToken = await UserHelpers.GetTokenAndSaveToDatabase(_dbContext, email, token, api.OAuth?.AccessToken,
77+
api.OAuth?.RefreshToken, api.OAuth?.ExpiresUtc, user.username, user.id);
7278
if (string.IsNullOrWhiteSpace(bearerToken)) {
73-
return Redirect($"{siteUrl}/twitch-bot/login?error=2");
79+
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.InternalError}");
7480
}
7581

76-
return Redirect($"{siteUrl}/twitch-bot/login?token={bearerToken}");
82+
return Redirect($"{siteUrl}/twitch-bot/config?token={bearerToken}");
7783
}
7884
}

src/Nullinside.Api.TwitchBot/Nullinside.Api.TwitchBot.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Nullinside.Api.TwitchBot_HostAddress = http://localhost:5086
1+
@Nullinside.Api.TwitchBot_HostAddress = http://localhost:5941
22

33
GET {{Nullinside.Api.TwitchBot_HostAddress}}/weatherforecast/
44
Accept: application/json

src/Nullinside.Api.TwitchBot/appsettings.Development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"Microsoft.AspNetCore": "Warning",
66
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
77
}
8+
},
9+
"Api": {
10+
"SiteUrl": "http://localhost:4200"
811
}
912
}

src/Nullinside.Api.TwitchBot/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
77
}
88
},
9-
"AllowedHosts": "*"
9+
"AllowedHosts": "*",
10+
"Api": {
11+
"SiteUrl": "https://nullinside.com"
12+
}
1013
}

0 commit comments

Comments
 (0)