Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Random text being shown in email value in Token Authentication, instead of "string" as default value #852

Closed
Sarmadjavediqbal opened this issue Apr 15, 2023 · 6 comments

Comments

@Sarmadjavediqbal
Copy link

Describe the bug
A clear and concise description of what the bug is.

Expected behavior
Following should be displayed:
{
"email": "string",
"password": "string"
}
image

Instead it is displaying as follows:
{
"email": "hy3%5s4uFhBD<yJfxBfsTT@BBEM;coO2irsX[}{AZ -qKKt(e:x",
"password": "string"
}

Screenshots
image

Maybe this error is occurring on my end. but I can't figure out how to solve this issue.

@Sarmadjavediqbal
Copy link
Author

Hi again. could someone tell me what could be wrong here??? I am still trying to solve this error but can't figure out what is causing this random string to occur. Kindly reply as soon as possible.

@eos95
Copy link

eos95 commented Apr 25, 2023

Check : TokensController-> GetIpAddress() -> as master

@Sarmadjavediqbal
Copy link
Author

Sarmadjavediqbal commented Apr 25, 2023

Check : TokensController-> GetIpAddress() -> as master

Following is the TokensController. Still this bug is not fixed.

public sealed class TokensController : VersionedNeutralApiController
{
private readonly ITokenService _tokenService;

public TokensController(ITokenService tokenService) => _tokenService = tokenService;

[HttpPost]
[AllowAnonymous]
[TenantIdHeader]
[OpenApiOperation("Request an access token using credentials.", "")]
public Task<TokenResponse> GetTokenAsync(TokenRequest request, CancellationToken cancellationToken)
{
    return _tokenService.GetTokenAsync(request, GetIpAddress(), cancellationToken);
}

[HttpPost("refresh")]
[AllowAnonymous]
[TenantIdHeader]
[OpenApiOperation("Request an access token using a refresh token.", "")]
[ApiConventionMethod(typeof(FSHApiConventions), nameof(FSHApiConventions.Search))]
public Task<TokenResponse> RefreshAsync(RefreshTokenRequest request)
{
    return _tokenService.RefreshTokenAsync(request, GetIpAddress());
}

private string? GetIpAddress() =>
    Request.Headers.ContainsKey("X-Forwarded-For")
        ? Request.Headers["X-Forwarded-For"].ToString() ?? "N/A"
        : HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString() ?? "N/A";

}

The random string changes on pressing the reset button in token authentication.

image

@eos95
Copy link

eos95 commented Apr 25, 2023

private string GetIpAddress() =>
Request.Headers.ContainsKey("X-Forwarded-For")
? Request.Headers["X-Forwarded-For"]
: HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString() ?? "N/A";

@Sarmadjavediqbal
Copy link
Author

private string GetIpAddress() => Request.Headers.ContainsKey("X-Forwarded-For") ? Request.Headers["X-Forwarded-For"] : HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString() ?? "N/A";

Still not fixed. Is there any other way to fix this bug??? Is it possible that any nuget package is not compatible with this ???

@Sarmadjavediqbal
Copy link
Author

Fixed it some how. I uninstalled (ZymLabs.NSwag.FluentValidation.AspNetCore) nuget package and installed a previous version of this package. It did not work but then I reinstalled the latest version (0.6.2) of (ZymLabs.NSwag.FluentValidation.AspNetCore) and the bug was gone. Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants