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