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

feat(auth): edit cookie options #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/starterProject/WebAPI/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -116,7 +116,14 @@ private string getRefreshTokenFromCookies()

private void setRefreshTokenToCookie(RefreshToken refreshToken)
{
CookieOptions cookieOptions = new() { HttpOnly = true, Expires = DateTime.UtcNow.AddDays(7) };
CookieOptions cookieOptions =
new()
{
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.None,
Expires = DateTime.UtcNow.AddDays(7)
};
Response.Cookies.Append(key: "refreshToken", refreshToken.Token, cookieOptions);
}
}

Unchanged files with check annotations Beta

{
_loginCommand.UserForLoginDto = new() { Email = "example@kodlama.io", Password = "123456" };
LoggedResponse result = await _loginCommandHandler.Handle(_loginCommand, CancellationToken.None);
Assert.NotNull(result.AccessToken.Token);

Check warning on line 94 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 94 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.
}
[Fact]
LoggedResponse result = await _loginCommandHandler.Handle(_loginCommand, CancellationToken.None);
TokenOptions? tokenOptions = _configuration.GetSection("TokenOptions").Get<TokenOptions>();
bool tokenExpiresInTime =
DateTime.Now.AddMinutes(tokenOptions.AccessTokenExpiration + 1) > result.AccessToken.ExpirationDate;

Check warning on line 104 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 104 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 104 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 104 in tests/StarterProject.Application.Tests/Features/Auth/Commands/Login/LoginTests.cs

GitHub Actions / build

Dereference of a possibly null reference.
Assert.True(tokenExpiresInTime, "Access token expiration time is invalid.");
}