Skip to content

Commit bbc1b93

Browse files
author
Vadim Belov
committed
Support cookie-based refresh tokens in BaseAuthController
Enhanced the `RefreshToken` method to support retrieving the refresh token from a cookie if it is not provided in the request body. Introduced a `useCookie` flag to determine the source of the refresh token. If using a cookie, a new random refresh token is generated upon response. This improves flexibility in token handling by accommodating both cookie-based and body-based refresh token workflows.
1 parent a6d08f9 commit bbc1b93

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/EasyExtensions.AspNetCore.Authorization/Controllers/BaseAuthController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordRequest
7373
[HttpPost("refresh")]
7474
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequestDto request)
7575
{
76-
if (string.IsNullOrWhiteSpace(request.RefreshToken))
76+
bool useCookie = string.IsNullOrWhiteSpace(request.RefreshToken);
77+
if (useCookie)
7778
{
7879
if (Request.Cookies.TryGetValue("refresh_token", out string? cookieRefreshToken))
7980
{
@@ -106,7 +107,7 @@ public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequestDto
106107
return Ok(new TokenPairDto
107108
{
108109
AccessToken = accessToken,
109-
RefreshToken = newRefreshToken
110+
RefreshToken = useCookie ? StringHelpers.CreateRandomString(64) : newRefreshToken
110111
});
111112
}
112113

0 commit comments

Comments
 (0)