implement api call to get uids based on secret key
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user