Handle Unauthorized service extension (Legacy)

Handle Unauthorized service extension (Legacy)

ℹ️
This topic refers to legacy configuration syntax. App gateways are now defined as Proxy apps.

By default, Maverics will return an HTTP forbidden (403), or redirect to the unauthorizedPage when a request is denied. However, it can be useful to control the exact response that is written to a client.

HandleUnauthorizedSE

appgateways:
  - name: example
    # ...
    
    handleUnauthorizedSE:
      funcName: HandleUnauthorized
      file: /etc/maverics/extensions/handleUnauthorized.go

/etc/maverics/extensions/handleUnauthorized.go

package main

import (
	"fmt"
	"net/http"

	"maverics/app"
	"maverics/log"
)

func HandleUnauthorized(
	ag *app.AppGateway,
	rw http.ResponseWriter,
	req *http.Request,
) {
	log.Debug("msg", "handling unauthorized request")

	http.Error(
		rw,
		fmt.Sprintf(
			"Access denied to %s. Please contact [email protected] for help.",
			req.URL.Path,
		),
		http.StatusUnauthorized,
	)
}