mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-26 01:07:52 +00:00
32 lines
783 B
Go
32 lines
783 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/jwt"
|
|
)
|
|
|
|
func (h *BaseHandler) Temporal(w http.ResponseWriter, r *http.Request, principal *AuthenticatedPrincipal) {
|
|
proxy := httputil.NewSingleHostReverseProxy(&url.URL{
|
|
Host: h.config.Temporal.UIHost,
|
|
Scheme: "http",
|
|
})
|
|
|
|
originalDirector := proxy.Director
|
|
|
|
proxy.Director = func(r *http.Request) {
|
|
originalDirector(r)
|
|
// Add authentication token to be able to access temporal.
|
|
// FIXME: Maybe cache it somehow so we don't generate it on every request?
|
|
token, _ := jwt.NewTokenForUser(
|
|
h.config.Jwt.PrivateKey,
|
|
h.config.Jwt.PublicKey,
|
|
principal.User.Email,
|
|
)
|
|
r.Header.Add("Authorization", "Bearer "+token)
|
|
}
|
|
|
|
proxy.ServeHTTP(w, r)
|
|
}
|