func getRedirectURI(consent ConsentRequest) (string, error) {
	authPath := kongProxyEndpoint + apiPath + "/oauth2/authorize"
	data := url.Values{}
	data.Set("client_id", consent.ClientID)
	data.Add("response_type", consent.ResponseType)
	data.Add("scope", strings.Replace(consent.Scopes, ",", " ", -1))
	data.Add("provision_key", provisionKey)
	data.Add("authenticated_userid", "client-userid")
	req, err := http.NewRequest(http.MethodPost, authPath, bytes.NewBufferString(data.Encode()))
	if err != nil {
		return "", err
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
	body, exErr := executeRequest(req)
	if exErr != nil {
		return "", exErr
	}
	response := AuthorizeResponse{}
	jsonErr := json.Unmarshal(body, &response)
	if jsonErr != nil {
		return "", jsonErr
	}
	return response.RedirectURI, nil
}
getRedirectURI queries Kong's '/oauth2/authorize' endpoint and returns the 'redirect_uri' property
package main
import (
	"bytes"
	"crypto/tls"
	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"strings"
	"time"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/sessions"
)
var (
	demoClientID           = os.Getenv("DEMO_CLIENT_ID")
	kongAdminEndpoint      = os.Getenv("KONG_ADMIN_ENDPOINT")
	kongProxyEndpoint      = os.Getenv("KONG_PROXY_ENDPOINT")
	apiPath                = os.Getenv("API_PATH")
	provisionKey           = os.Getenv("PROVISION_KEY")
	cookieNameForSessionID = "kongOAuthConsentApp"
	sess                   = sessions.New(sessions.Config{Cookie: cookieNameForSessionID})
	userAgent              = "kong-oauth2-consent-app"
)
type Credentials struct {
	Username string
	Password string
}
type ConsentRequest struct {
	ClientID     string
	ResponseType string
	Scopes       string
}
type OAuth2Credential struct {
	ApplicationName string `json:"name"`
}
type OAuth2Credentials struct {
	Data []OAuth2Credential `json:"data"`
}
type AuthorizeResponse struct {
	RedirectURI string `json:"redirect_uri"`
}
func main() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	app := iris.New()
	app.RegisterView(iris.HTML("./templates", ".html"))
	app.Get("/", getIndex)
	app.Get("/consent", getConsent)
	app.Post("/consent", postConsent)
	app.Get("/login", getLogin)
	app.Post("/login", postLogin)
	app.Get("/logout", getLogout)
	app.Run(iris.Addr("localhost:8080"))
}
func executeRequest(req *http.Request) ([]byte, error) {
	req.Header.Set("User-Agent", userAgent)
	httpClient := http.Client{
		Timeout: time.Second * 2,
	}
	res, getErr := httpClient.Do(req)
	if getErr != nil {
		return nil, getErr
	}
	defer res.Body.Close()
	body, readErr := ioutil.ReadAll(res.Body)
	if readErr != nil {
		return nil, readErr
	}
	return body, nil
}
func getApplicationName(clientID string) (string, error) {
	url := kongAdminEndpoint + "/oauth2?client_id=" + clientID
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		return "", err
	}
	body, exErr := executeRequest(req)
	if exErr != nil {
		return "", exErr
	}
	creds := OAuth2Credentials{}
	jsonErr := json.Unmarshal(body, &creds)
	if jsonErr != nil {
		return "", jsonErr
	}
	return creds.Data[0].ApplicationName, nil
}