feat: logout
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m51s
Build and Deploy Go App / deploy (push) Successful in 40s

This commit is contained in:
nihonium 2025-12-06 07:01:38 +03:00
parent 714ef57027
commit 69eacd7240
Signed by: nihonium
GPG key ID: 0251623741027CFC
3 changed files with 94 additions and 0 deletions

View file

@ -284,6 +284,22 @@ func (s Server) RefreshTokens(ctx context.Context, req auth.RefreshTokensRequest
return auth.RefreshTokens200Response{}, nil
}
func (s Server) Logout(ctx context.Context, req auth.LogoutRequestObject) (auth.LogoutResponseObject, error) {
// TODO: get current tokens and add them to block list
ginCtx, ok := ctx.Value(gin.ContextKey).(*gin.Context)
if !ok {
log.Print("failed to get gin context")
return auth.Logout500Response{}, fmt.Errorf("failed to get gin.Context from context.Context")
}
// Delete cookies by setting MaxAge negative
ginCtx.SetCookie("access_token", "", -1, "/api", "", true, true)
ginCtx.SetCookie("refresh_token", "", -1, "/auth", "", true, true)
ginCtx.SetCookie("xsrf_token", "", -1, "/", "", false, false)
return auth.Logout200Response{}, nil
}
func ExtractBearerToken(header string) (string, error) {
const prefix = "Bearer "
if len(header) <= len(prefix) || header[:len(prefix)] != prefix {