Add Steam OpenID authentication
Deploy Promiscuity Auth API / deploy (push) Failing after 20s
Deploy Promiscuity Character API / deploy (push) Failing after 19s
Deploy Promiscuity Crafting API / deploy (push) Failing after 20s
Deploy Promiscuity Inventory API / deploy (push) Failing after 19s
Deploy Promiscuity Locations API / deploy (push) Failing after 19s
Deploy Promiscuity Mail API / deploy (push) Failing after 20s
Deploy Promiscuity World API / deploy (push) Failing after 20s
k8s smoke test / test (push) Failing after 20s

This commit is contained in:
2026-07-20 00:30:06 -05:00
parent 18c3d6fc5d
commit cde0e28e44
16 changed files with 564 additions and 29 deletions
@@ -1,5 +1,7 @@
using AuthApi.Models;
using MongoDB.Bson;
using MongoDB.Driver;
using System.Text.RegularExpressions;
namespace AuthApi.Services;
@@ -17,6 +19,12 @@ public class UserService
var keys = Builders<User>.IndexKeys.Ascending(u => u.Username);
_col.Indexes.CreateOne(new CreateIndexModel<User>(keys, new CreateIndexOptions { Unique = true }));
var steamKeys = Builders<User>.IndexKeys.Ascending(u => u.SteamId);
_col.Indexes.CreateOne(new CreateIndexModel<User>(steamKeys, new CreateIndexOptions<User>
{
Unique = true,
PartialFilterExpression = new BsonDocument("SteamId", new BsonDocument("$type", "string"))
}));
}
public async Task<User?> GetByUsernameAsync(string username) =>
@@ -28,11 +36,36 @@ public class UserService
public async Task<User?> GetByEmailAsync(string email) =>
await _col.Find(u => u.Email == email).FirstOrDefaultAsync();
public async Task<List<User>> GetByLoginCandidatesAsync(string login)
{
var normalized = login.Trim();
var usernameMatch = await GetByUsernameAsync(normalized);
if (usernameMatch is not null)
return [usernameMatch];
var emailPattern = new BsonRegularExpression($"^{Regex.Escape(normalized)}$", "i");
return await _col.Find(Builders<User>.Filter.Regex(u => u.Email, emailPattern)).ToListAsync();
}
public async Task<User?> GetBySteamIdAsync(string steamId) =>
await _col.Find(u => u.SteamId == steamId).FirstOrDefaultAsync();
public Task CreateAsync(User user) => _col.InsertOneAsync(user);
public Task UpdateAsync(User user) =>
_col.ReplaceOneAsync(u => u.Id == user.Id, user);
public async Task<bool> TryLinkSteamAsync(string userId, string steamId, string refreshToken, DateTime refreshExpiry)
{
var filter = Builders<User>.Filter.Eq(u => u.Id, userId) &
(Builders<User>.Filter.Eq(u => u.SteamId, null) | Builders<User>.Filter.Eq(u => u.SteamId, steamId));
var update = Builders<User>.Update
.Set(u => u.SteamId, steamId)
.Set(u => u.RefreshToken, refreshToken)
.Set(u => u.RefreshTokenExpiry, refreshExpiry);
var result = await _col.UpdateOneAsync(filter, update);
return result.MatchedCount == 1;
}
public Task DeleteAsync(string id) => _col.DeleteOneAsync(u => u.Id == id);
public Task<List<User>> GetAllAsync() =>