Skip to content

Commit

Permalink
Attempt to fix JWT handling
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 29, 2024
1 parent 9af9b5d commit fa32f94
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions osu.Server.Spectator/Database/DatabaseAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ public class DatabaseAccess : IDatabaseAccess
{
private MySqlConnection? openConnection;

public async Task<int?> GetUserIdFromTokenAsync(JwtSecurityToken jwtToken)
public async Task<int?> GetUserIdFromTokenAsync(JsonWebToken jwtToken)
{
var connection = await getConnectionAsync();

Expand Down
4 changes: 2 additions & 2 deletions osu.Server.Spectator/Database/IDatabaseAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +18,7 @@ public interface IDatabaseAccess : IDisposable
/// Returns the database ID of the user to whom the supplied <paramref name="jwtToken"/> belongs.
/// Will be <c>null</c> if the token does not exist, has expired or has been revoked.
/// </summary>
Task<int?> GetUserIdFromTokenAsync(JwtSecurityToken jwtToken);
Task<int?> GetUserIdFromTokenAsync(JsonWebToken jwtToken);

/// <summary>
/// Whether the user with the given <paramref name="userId"/> is currently restricted.
Expand Down

0 comments on commit fa32f94

Please sign in to comment.