--- description: >- Controller for managing token refresh operations, allowing users to refresh their access tokens using a valid refresh token. --- # RefreshController ### Controller Description * **Route**: `api/auth/token` * **Authorize**: Allows anonymous access (`[AllowAnonymous]`). ### Endpoints #### Refresh * **Description**: Refreshes an access token using a provided refresh token and returns a new access token and refresh token pair. * **Route**: `[POST] api/auth/token/refresh` * **HTTP Method**: `POST` * **Request**: * **Content-Type**: `application/json` * **Request Body**: `RefreshTokenRequest` object with the following structure: ```json { "refreshToken": "string" } ``` * **Responses**: * **200 OK**: Returns a new access token and refresh token upon successful refresh. ```json { "accessToken": "string", "refreshToken": "string" } ``` * **400 Bad Request**: If model validation fails or the refresh token is empty. ```json "Refresh token cant be empty." ``` * **401 Unauthorized**: If the refresh token is invalid or authorization fails. ```json "Invalid refresh token" ``` * **500 Internal Server Error**: Indicates an unexpected error. ```json "An unexpected error occurred." ``` ### Data Models #### RefreshTokenRequest * **Description**: Model for refresh token request data. * **Structure**: ```json { "refreshToken": "string" } ``` #### RefreshTokenResponse * **Description**: Model for refresh token response data. * **Structure**: ```json { "accessToken": "string", "refreshToken": "string" } ``` ### Error Handling * **Invalid User ID**: Not applicable (handled by session service). * **Invalid Operations**: Returns `400 Bad Request` if the refresh token is empty or invalid. * **Unauthorized Access**: Returns `401 Unauthorized` if the refresh token fails authorization. * **Unexpected Errors**: General exceptions are caught, logged, and returned as `500 Internal Server Error`. ### Logging * Logs warnings for invalid or failed refresh token attempts. * Logs errors for unexpected exceptions during token refresh.