From fa32f944b2eeceedaef8c4aebc7219459260b62f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 Jan 2024 02:52:52 +0900 Subject: [PATCH] Attempt to fix JWT handling --- .../Authentication/ConfigureJwtBearerOptions.cs | 4 ++-- osu.Server.Spectator/Database/DatabaseAccess.cs | 4 ++-- osu.Server.Spectator/Database/IDatabaseAccess.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Server.Spectator/Authentication/ConfigureJwtBearerOptions.cs b/osu.Server.Spectator/Authentication/ConfigureJwtBearerOptions.cs index 95113ed1..6dcdc5c2 100644 --- a/osu.Server.Spectator/Authentication/ConfigureJwtBearerOptions.cs +++ b/osu.Server.Spectator/Authentication/ConfigureJwtBearerOptions.cs @@ -2,11 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.IdentityModel.Tokens.Jwt; using System.IO; using System.Security.Cryptography; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.Extensions.Options; +using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Tokens; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; @@ -40,7 +40,7 @@ public void Configure(JwtBearerOptions options) { OnTokenValidated = async context => { - var jwtToken = (JwtSecurityToken)context.SecurityToken; + var jwtToken = (JsonWebToken)context.SecurityToken; int tokenUserId = int.Parse(jwtToken.Subject); using (var db = databaseFactory.GetInstance()) diff --git a/osu.Server.Spectator/Database/DatabaseAccess.cs b/osu.Server.Spectator/Database/DatabaseAccess.cs index 91841227..f94dde3e 100644 --- a/osu.Server.Spectator/Database/DatabaseAccess.cs +++ b/osu.Server.Spectator/Database/DatabaseAccess.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Threading.Tasks; using Dapper; +using Microsoft.IdentityModel.JsonWebTokens; using MySqlConnector; using osu.Game.Online.Metadata; using osu.Game.Online.Multiplayer; @@ -20,7 +20,7 @@ public class DatabaseAccess : IDatabaseAccess { private MySqlConnection? openConnection; - public async Task GetUserIdFromTokenAsync(JwtSecurityToken jwtToken) + public async Task GetUserIdFromTokenAsync(JsonWebToken jwtToken) { var connection = await getConnectionAsync(); diff --git a/osu.Server.Spectator/Database/IDatabaseAccess.cs b/osu.Server.Spectator/Database/IDatabaseAccess.cs index a96605f9..c33bba8b 100644 --- a/osu.Server.Spectator/Database/IDatabaseAccess.cs +++ b/osu.Server.Spectator/Database/IDatabaseAccess.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; using System.Threading.Tasks; +using Microsoft.IdentityModel.JsonWebTokens; using osu.Game.Online.Metadata; using osu.Game.Online.Multiplayer; using osu.Game.Scoring; @@ -18,7 +18,7 @@ public interface IDatabaseAccess : IDisposable /// Returns the database ID of the user to whom the supplied belongs. /// Will be null if the token does not exist, has expired or has been revoked. /// - Task GetUserIdFromTokenAsync(JwtSecurityToken jwtToken); + Task GetUserIdFromTokenAsync(JsonWebToken jwtToken); /// /// Whether the user with the given is currently restricted.