Merge pull request 'adding test endpoint for testing the expiry token' (#39) from feature/responses-v2 into dev
Reviewed-on: winter-access/backend_nam#39
This commit is contained in:
commit
fa464888c6
|
|
@ -27,6 +27,7 @@ func (c *AuthController) Route() {
|
||||||
auth.POST("/login", c.login)
|
auth.POST("/login", c.login)
|
||||||
auth.POST("/logout", c.logout)
|
auth.POST("/logout", c.logout)
|
||||||
auth.POST("/validate", c.validateToken)
|
auth.POST("/validate", c.validateToken)
|
||||||
|
auth.POST("/test-token-expiry", c.testTokenExpiry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,3 +103,34 @@ func (c *AuthController) validateToken(ctx *gin.Context) {
|
||||||
|
|
||||||
common.SingleResponses(ctx, "Token is valid", response)
|
common.SingleResponses(ctx, "Token is valid", response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *AuthController) testTokenExpiry(ctx *gin.Context) {
|
||||||
|
token := ctx.GetHeader("Authorization")
|
||||||
|
if token == "" {
|
||||||
|
common.ErrorResponses(ctx, http.StatusBadRequest, "Authorization token required")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove "Bearer " prefix
|
||||||
|
if len(token) > 7 && token[:7] == "Bearer " {
|
||||||
|
token = token[7:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if token is expired
|
||||||
|
_, err := c.authUC.ValidateToken(token)
|
||||||
|
if err != nil {
|
||||||
|
response := gin.H{
|
||||||
|
"expired": true,
|
||||||
|
"message": err.Error(),
|
||||||
|
}
|
||||||
|
common.SingleResponses(ctx, "Token expiry test result", response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response := gin.H{
|
||||||
|
"expired": false,
|
||||||
|
"message": "Token is still valid",
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(ctx, "Token expiry test result", response)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue