implement api call to get uids based on secret key
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: 040add0608...dc1c409ec6
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using StackExchange.Redis.Extensions.Core.Abstractions;
|
using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace MareSynchronosAuthService.Controllers;
|
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.");
|
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")]
|
[Authorize(Policy = "OAuthToken")]
|
||||||
[HttpPost(MareAuth.OAuth_RenewOAuthToken)]
|
[HttpPost(MareAuth.OAuth_RenewOAuthToken)]
|
||||||
public IActionResult RenewOAuthToken()
|
public IActionResult RenewOAuthToken()
|
||||||
|
|||||||
Reference in New Issue
Block a user