From effa2d93d434172e5c50942aeac8dcf0d8b1c3c5 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 31 Oct 2021 01:29:14 -0400 Subject: [PATCH 1/4] Updates /tg/ forums OAuth support --- .../Security/OAuth/TGForumsOAuthValidator.cs | 106 ++---------------- 1 file changed, 11 insertions(+), 95 deletions(-) diff --git a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs index 309c479a07..86902f89db 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs @@ -19,20 +19,16 @@ namespace Tgstation.Server.Host.Security.OAuth /// /// for /tg/ forums. /// - sealed class TGForumsOAuthValidator : BaseOAuthValidator + sealed class TGForumsOAuthValidator : GenericOAuthValidator { - /// - /// Amount of minutes until unused sessions that were created are forgotten. - /// - const uint SessionRetentionMinutes = 10; - /// public override OAuthProvider Provider => OAuthProvider.TGForums; - /// - /// The active session. - /// - readonly List> sessions; + /// + protected override Uri TokenUrl => new Uri("https://tgstation13.org/phpBB/app.php/tgapi/oauth/token"); + + /// + protected override Uri UserInformationUrl => new Uri("https://tgstation13.org/phpBB/app.php/tgapi/user/me"); /// /// Initializes a new instance of the class. @@ -52,98 +48,18 @@ namespace Tgstation.Server.Host.Security.OAuth logger, oAuthConfiguration) { - sessions = new List>(); } /// - public override async Task GetProviderInfo(CancellationToken cancellationToken) + protected override string DecodeTokenPayload(dynamic responseJson) { - var expiredSessions = sessions.RemoveAll(x => x.Item2.AddMinutes(SessionRetentionMinutes) < DateTimeOffset.UtcNow); - if (expiredSessions > 0) - Logger.LogTrace("Expired {0} sessions", expiredSessions); - - Logger.LogTrace("Creating new session..."); - try - { - UriBuilder builder = new UriBuilder("https://tgstation13.org/phpBB/oauth_create_session.php") - { - Query = $"site_private_token={HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(OAuthConfiguration.ClientSecret)))}&return_uri={HttpUtility.UrlEncode(OAuthConfiguration.RedirectUrl.ToString())}", - }; - - using var request = new HttpRequestMessage(HttpMethod.Get, builder.Uri); - using var httpClient = CreateHttpClient(); - - using var response = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); - response.EnsureSuccessStatusCode(); - - var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var newSession = JsonConvert.DeserializeObject(json, SerializerSettings()); - - if (newSession.Status != TGBaseResponse.OkStatus) - { - Logger.LogWarning("Invalid status from /tg/ API! Status: {0}, Error: {1}", newSession.Status, newSession.Error); - return null; - } - - sessions.Add( - Tuple.Create( - newSession, - DateTimeOffset.UtcNow)); - return new OAuthProviderInfo - { - ClientId = newSession.SessionPublicToken, - RedirectUri = OAuthConfiguration.RedirectUrl, - }; - } - catch (Exception ex) - { - Logger.LogWarning(ex, "Failed to create TG Forums session!"); - return null; - } + throw new NotImplementedException(); } /// - public override async Task ValidateResponseCode(string code, CancellationToken cancellationToken) - { - try - { - var sessionTuple = sessions.FirstOrDefault(x => x.Item1.SessionPublicToken == code); - if (sessionTuple == null) - { - Logger.LogWarning("No known session with this code active!"); - return null; - } + protected override string DecodeUserInformationPayload(dynamic responseJson) => responseJson.phpbb_username; - Logger.LogTrace("Validating session..."); - - UriBuilder builder = new UriBuilder("https://tgstation13.org/phpBB/oauth_get_session_info.php") - { - Query = $"site_private_token={HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(OAuthConfiguration.ClientSecret)))}&session_private_token={HttpUtility.UrlEncode(sessionTuple.Item1.SessionPrivateToken)}", - }; - - using var request = new HttpRequestMessage(HttpMethod.Get, builder.Uri); - using var httpClient = CreateHttpClient(); - - using var response = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); - response.EnsureSuccessStatusCode(); - - var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var sessionInfo = JsonConvert.DeserializeObject(json, SerializerSettings()); - - if (sessionInfo.Status != TGBaseResponse.OkStatus) - { - Logger.LogWarning("Invalid status from /tg/ API! Status: {0}, Error: {1}", sessionInfo.Status, sessionInfo.Error); - return null; - } - - sessions.Remove(sessionTuple); - return sessionInfo.PhpbbUsername; - } - catch (Exception ex) - { - Logger.LogWarning(ex, "Failed to create TG Forums session!"); - return null; - } - } + /// + protected override OAuthTokenRequest CreateTokenRequest(string code) => new OAuthTokenRequest(OAuthConfiguration, code, "user"); } } From 402e85bb5867b533cb8528cb0c39b2392bc47ab8 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 28 Jan 2022 16:42:23 -0500 Subject: [PATCH 2/4] Pin ibm-openapi-validator to 0.51.3 --- .github/workflows/ci-suite.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index dd97869858..e91cc39de5 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -115,7 +115,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - + - name: Upgrade NPM run: sudo npm install -g npm @@ -136,7 +136,7 @@ jobs: - name: Checkout uses: actions/checkout@v1 - + - name: Upgrade NPM run: sudo npm install -g npm @@ -166,7 +166,7 @@ jobs: - name: Checkout uses: actions/checkout@v1 - + - name: Upgrade NPM run: npm install -g npm @@ -201,7 +201,7 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} - + - name: Upgrade NPM run: npm install -g npm @@ -328,7 +328,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: 12.x - + - name: Upgrade NPM run: npm install -g npm @@ -437,7 +437,7 @@ jobs: node-version: 12.x - name: Install IBM OpenAPI Validator - run: npm i -g ibm-openapi-validator + run: npm i -g ibm-openapi-validator@0.51.3 - name: Checkout uses: actions/checkout@v1 From 2dd553616d246838ea9e641d73970aaf59aa1f7d Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:06:48 -0500 Subject: [PATCH 3/4] Update ControlPanelVersion.props --- build/ControlPanelVersion.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ControlPanelVersion.props b/build/ControlPanelVersion.props index 801c4295d0..15b537bc81 100644 --- a/build/ControlPanelVersion.props +++ b/build/ControlPanelVersion.props @@ -1,6 +1,6 @@ - 3.0.0 + 3.1.0 From d7c2a364ac5b5ec1d4230970d1b2a4236e7cc745 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 28 Jan 2022 19:13:27 -0500 Subject: [PATCH 4/4] Version bump to 4.16.0 --- build/Version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Version.props b/build/Version.props index 2fa65b2f96..a201a3d3f7 100644 --- a/build/Version.props +++ b/build/Version.props @@ -3,7 +3,7 @@ - 4.15.7 + 4.16.0 4.1.0 9.3.0 9.3.1