Update NeutrinoController.cs
This commit is contained in:
@@ -13,10 +13,11 @@ namespace API.Controllers.Neutrino;
|
||||
[ApiController]
|
||||
public class NeutrinoController(
|
||||
INeutrinoAuthorizationService authorizationService,
|
||||
ILogger<NeutrinoController> logger,
|
||||
IOptions<NeutrinoOptions> options) : ControllerBase
|
||||
{
|
||||
private readonly NeutrinoOptions _options = options.Value;
|
||||
|
||||
|
||||
// Photon sends the request with Content-Type: text/plain instead of application/json.
|
||||
[HttpPost("authorize")]
|
||||
public async Task<ActionResult<NeutrinoAuthenticateResponse>> AuthorizeNeutrinoAsync(
|
||||
@@ -25,7 +26,7 @@ public class NeutrinoController(
|
||||
{
|
||||
if (_options.ValidateSecret && secret != _options.Secret)
|
||||
return Forbid();
|
||||
|
||||
|
||||
using var reader = new StreamReader(Request.Body);
|
||||
string rawText = await reader.ReadToEndAsync(ct);
|
||||
|
||||
@@ -50,18 +51,33 @@ public class NeutrinoController(
|
||||
return Ok(
|
||||
NeutrinoAuthenticateResponse.Failure(
|
||||
AuthenticationResultCode.InvalidParameters));
|
||||
|
||||
logger.LogInformation(
|
||||
"Neutrino authorization request received for profile {ProfileId}",
|
||||
request.ProfileId);
|
||||
|
||||
var result = await authorizationService.AuthorizeAsync(
|
||||
new AuthorizeNeutrinoCommand(
|
||||
request.ProfileId,
|
||||
request.AccessToken),
|
||||
ct);
|
||||
|
||||
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Neutrino authorization failed for profile {ProfileId}: {Failure}",
|
||||
request.ProfileId,
|
||||
result.Failure);
|
||||
return Ok(
|
||||
NeutrinoAuthenticateResponse.Failure(
|
||||
MapFailure(result.Failure)));
|
||||
}
|
||||
|
||||
logger.LogInformation(
|
||||
"Neutrino authorization succeeded for profile {ProfileId}, nickname {Nickname}",
|
||||
result.UserId,
|
||||
result.Nickname);
|
||||
|
||||
return Ok(
|
||||
NeutrinoAuthenticateResponse.Success(
|
||||
result.UserId!,
|
||||
@@ -72,4 +88,4 @@ public class NeutrinoController(
|
||||
=> failure == NeutrinoAuthorizationFailure.InvalidParameters
|
||||
? AuthenticationResultCode.InvalidParameters
|
||||
: AuthenticationResultCode.AuthenticationFailedWrongCredentials;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user