mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 20:57:22 +01:00
implement api call to get uids based on secret key
This commit is contained in:
parent
19d819045c
commit
7acd36bb79
3 changed files with 25 additions and 1 deletions
2
MareAPI
2
MareAPI
|
|
@ -1 +1 @@
|
|||
Subproject commit 040add06083f76e5b41e64b8842339266a046871
|
||||
Subproject commit dc1c409ec65934fe3c50889d0517bc68f5fda431
|
||||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace MareSynchronosAuthService.Controllers;
|
||||
|
||||
|
|
|
|||
|
|
@ -169,6 +169,29 @@ public class OAuthController : AuthControllerBase
|
|||
return Ok("The OAuth2 token was generated. The plugin will grab it automatically. You can close this browser tab.");
|
||||
}
|
||||
|
||||
[Authorize(Policy = "OAuthToken")]
|
||||
[HttpPost(MareAuth.OAuth_GetUIDsBasedOnSecretKeys)]
|
||||
public async Task<Dictionary<string, string>> GetUIDsBasedOnSecretKeys([FromBody] List<string> secretKeys)
|
||||
{
|
||||
if (!secretKeys.Any())
|
||||
return [];
|
||||
|
||||
using var dbContext = await MareDbContextFactory.CreateDbContextAsync();
|
||||
|
||||
Dictionary<string, string> secretKeysToUIDDict = secretKeys.Distinct().ToDictionary(k => k, _ => string.Empty, StringComparer.Ordinal);
|
||||
foreach (var key in secretKeys)
|
||||
{
|
||||
var shaKey = StringUtils.Sha256String(key);
|
||||
var associatedAuth = await dbContext.Auth.AsNoTracking().SingleOrDefaultAsync(a => a.HashedKey == shaKey);
|
||||
if (associatedAuth != null)
|
||||
{
|
||||
secretKeysToUIDDict[key] = associatedAuth.UserUID;
|
||||
}
|
||||
}
|
||||
|
||||
return secretKeysToUIDDict;
|
||||
}
|
||||
|
||||
[Authorize(Policy = "OAuthToken")]
|
||||
[HttpPost(MareAuth.OAuth_RenewOAuthToken)]
|
||||
public IActionResult RenewOAuthToken()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue