⚗️ Put steam connection to test
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
using System.Text.Json;
|
|
||||||
using DysonNetwork.Shared.Cache;
|
using DysonNetwork.Shared.Cache;
|
||||||
|
|
||||||
namespace DysonNetwork.Pass.Auth.OpenId;
|
namespace DysonNetwork.Pass.Auth.OpenId;
|
||||||
@@ -74,51 +73,21 @@ public class SteamOidcService(
|
|||||||
throw new InvalidOperationException("Invalid Steam ID format");
|
throw new InvalidOperationException("Invalid Steam ID format");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch user information from Steam API
|
// Create user information with Steam ID
|
||||||
var userInfo = await GetUserInfoAsync(steamId);
|
var userInfo = await GetUserInfoAsync(steamId);
|
||||||
|
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OidcUserInfo> GetUserInfoAsync(string steamId)
|
private Task<OidcUserInfo> GetUserInfoAsync(string steamId)
|
||||||
{
|
{
|
||||||
var config = GetProviderConfig();
|
return Task.FromResult(new OidcUserInfo
|
||||||
var apiKey = Configuration[$"Oidc:Steam:ApiKey"] ?? throw new InvalidOperationException("Steam API key not configured");
|
|
||||||
|
|
||||||
var client = HttpClientFactory.CreateClient();
|
|
||||||
var url = $"https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key={apiKey}&steamids={steamId}";
|
|
||||||
|
|
||||||
var response = await client.GetAsync(url);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
|
||||||
var steamResponse = JsonDocument.Parse(json).RootElement;
|
|
||||||
|
|
||||||
var players = steamResponse.GetProperty("response").GetProperty("players");
|
|
||||||
if (players.GetArrayLength() == 0)
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Steam user not found");
|
UserId = steamId,
|
||||||
}
|
|
||||||
|
|
||||||
var player = players[0];
|
|
||||||
var steamIdStr = player.GetProperty("steamid").GetString() ?? "";
|
|
||||||
var personaName = player.GetProperty("personaname").GetString() ?? "";
|
|
||||||
var avatarUrl = player.TryGetProperty("avatarfull", out var avatarElement)
|
|
||||||
? avatarElement.GetString()
|
|
||||||
: player.TryGetProperty("avatarmedium", out var mediumAvatarElement)
|
|
||||||
? mediumAvatarElement.GetString()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return new OidcUserInfo
|
|
||||||
{
|
|
||||||
UserId = steamIdStr,
|
|
||||||
DisplayName = personaName,
|
|
||||||
PreferredUsername = personaName,
|
|
||||||
ProfilePictureUrl = avatarUrl,
|
|
||||||
Provider = ProviderName,
|
Provider = ProviderName,
|
||||||
// Steam OpenID doesn't provide email
|
// Steam OpenID doesn't provide additional user info
|
||||||
Email = null,
|
Email = null,
|
||||||
EmailVerified = false
|
EmailVerified = false
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
<PackageReference Include="EFCore.BulkExtensions.PostgreSql" Version="9.0.2" />
|
<PackageReference Include="EFCore.BulkExtensions.PostgreSql" Version="9.0.2" />
|
||||||
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
|
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
|
||||||
<PackageReference Include="SpotifyAPI.Web" Version="7.2.1" />
|
<PackageReference Include="SpotifyAPI.Web" Version="7.2.1" />
|
||||||
|
<PackageReference Include="SteamWebAPI2" Version="4.4.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public static class ServiceCollectionExtensions
|
|||||||
services.AddScoped<OidcService, DiscordOidcService>();
|
services.AddScoped<OidcService, DiscordOidcService>();
|
||||||
services.AddScoped<OidcService, AfdianOidcService>();
|
services.AddScoped<OidcService, AfdianOidcService>();
|
||||||
services.AddScoped<OidcService, SpotifyOidcService>();
|
services.AddScoped<OidcService, SpotifyOidcService>();
|
||||||
|
services.AddScoped<OidcService, SteamOidcService>();
|
||||||
services.AddScoped<GoogleOidcService>();
|
services.AddScoped<GoogleOidcService>();
|
||||||
services.AddScoped<AppleOidcService>();
|
services.AddScoped<AppleOidcService>();
|
||||||
services.AddScoped<GitHubOidcService>();
|
services.AddScoped<GitHubOidcService>();
|
||||||
@@ -66,6 +67,7 @@ public static class ServiceCollectionExtensions
|
|||||||
services.AddScoped<DiscordOidcService>();
|
services.AddScoped<DiscordOidcService>();
|
||||||
services.AddScoped<AfdianOidcService>();
|
services.AddScoped<AfdianOidcService>();
|
||||||
services.AddScoped<SpotifyOidcService>();
|
services.AddScoped<SpotifyOidcService>();
|
||||||
|
services.AddScoped<SteamOidcService>();
|
||||||
|
|
||||||
services.AddControllers().AddJsonOptions(options =>
|
services.AddControllers().AddJsonOptions(options =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user