feat: logout
This commit is contained in:
parent
714ef57027
commit
69eacd7240
3 changed files with 94 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue