53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package auth
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service/service_auth"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Refresh handles the token rotation process.
|
|
// @Summary Refresh Access Token
|
|
// @Description Accepts a valid refresh token to issue a new access token and a rotated refresh token.
|
|
// @Tags Authentication
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param payload body service_auth.RefreshData true "Refresh Token Body"
|
|
// @Success 200 {object} service_auth.RefreshResult
|
|
// @Failure 400 {string} string "Invalid Input"
|
|
// @Failure 401 {string} string "Invalid Refresh Token"
|
|
// @Failure 500 {string} string "Internal Server Error"
|
|
// @Router /auth/refresh [post]
|
|
func (self *AuthHandler) Refresh(c *gin.Context) {
|
|
var refreshData service_auth.RefreshData
|
|
|
|
if err := c.ShouldBindJSON(&refreshData); err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusUser).
|
|
SetService(exception.ServiceAuth).
|
|
SetEndpoint(exception.EndpointAuthServiceRefresh).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorInvalidInput).
|
|
SetError(err).
|
|
Throw(c).
|
|
String()
|
|
|
|
utils.HttpResponse(c, 400, errorCode)
|
|
return
|
|
}
|
|
|
|
result := self.svc.Refresh(&service_auth.RefreshPayload{
|
|
Context: c,
|
|
Data: &refreshData,
|
|
})
|
|
|
|
if result.Common.Exception.Original != exception.CommonSuccess {
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
|
return
|
|
}
|
|
|
|
utils.HttpResponse(c, 200, result.Common.Exception.String(), result.Data)
|
|
}
|