feat: add logout endpoint
This commit is contained in:
parent
0e18f695cf
commit
e73ab26ebf
|
@ -121,3 +121,26 @@ func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClearAuthCookie(jc jape.Context, apiName string) {
|
||||||
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(apiName) > 0 && apiName != name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
http.SetCookie(jc.ResponseWriter, &http.Cookie{
|
||||||
|
Name: routeableApi.AuthTokenName(),
|
||||||
|
Value: "",
|
||||||
|
Expires: time.Now().Add(-1 * time.Hour),
|
||||||
|
Secure: true,
|
||||||
|
HttpOnly: true,
|
||||||
|
Path: "/",
|
||||||
|
Domain: routeableApi.Domain(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -304,6 +304,10 @@ func (a AccountAPI) accountInfo(jc jape.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AccountAPI) logout(c jape.Context) {
|
||||||
|
account.ClearAuthCookie(c, "")
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AccountAPI) Routes() (*httprouter.Router, error) {
|
func (a *AccountAPI) Routes() (*httprouter.Router, error) {
|
||||||
loginAuthMw2fa := authMiddleware(middleware.AuthMiddlewareOptions{
|
loginAuthMw2fa := authMiddleware(middleware.AuthMiddlewareOptions{
|
||||||
Identity: a.identity,
|
Identity: a.identity,
|
||||||
|
@ -375,6 +379,7 @@ func (a *AccountAPI) Routes() (*httprouter.Router, error) {
|
||||||
"POST /api/auth/otp/disable": middleware.ApplyMiddlewares(a.otpDisable, authMw, middleware.ProxyMiddleware),
|
"POST /api/auth/otp/disable": middleware.ApplyMiddlewares(a.otpDisable, authMw, middleware.ProxyMiddleware),
|
||||||
"POST /api/auth/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, middleware.ProxyMiddleware),
|
"POST /api/auth/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, middleware.ProxyMiddleware),
|
||||||
"POST /api/auth/password-reset/confirm": middleware.ApplyMiddlewares(a.passwordResetConfirm, middleware.ProxyMiddleware),
|
"POST /api/auth/password-reset/confirm": middleware.ApplyMiddlewares(a.passwordResetConfirm, middleware.ProxyMiddleware),
|
||||||
|
"POST /api/auth/logout": middleware.ApplyMiddlewares(a.logout, authMw, middleware.ProxyMiddleware),
|
||||||
"GET /*path": getHandler,
|
"GET /*path": getHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,12 @@ paths:
|
||||||
$ref: '#/components/schemas/LoginResponse'
|
$ref: '#/components/schemas/LoginResponse'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
|
/api/auth/logout:
|
||||||
|
post:
|
||||||
|
summary: Logout of account service
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Successfully logged out
|
||||||
/api/auth/register:
|
/api/auth/register:
|
||||||
post:
|
post:
|
||||||
summary: Register a new account
|
summary: Register a new account
|
||||||
|
|
Loading…
Reference in New Issue