Files
Govor/endpoints/authentication/refreshcontroller.md
T
2025-07-24 08:07:52 +00:00

2.4 KiB

description
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:

      {
        "refreshToken": "string"
      }
      
  • Responses:
    • 200 OK: Returns a new access token and refresh token upon successful refresh.

      {
        "accessToken": "string",
        "refreshToken": "string"
      }
      
    • 400 Bad Request: If model validation fails or the refresh token is empty.

      "Refresh token cant be empty."
      
    • 401 Unauthorized: If the refresh token is invalid or authorization fails.

      "Invalid refresh token"
      
    • 500 Internal Server Error: Indicates an unexpected error.

      "An unexpected error occurred."
      

Data Models

RefreshTokenRequest

  • Description: Model for refresh token request data.

  • Structure:

    {
      "refreshToken": "string"
    }
    

RefreshTokenResponse

  • Description: Model for refresh token response data.

  • Structure:

    {
      "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.