BaseURL configuration variable generalization
This commit is contained in:
parent
41748363d1
commit
33dbb6ea47
4
Makefile
4
Makefile
|
@ -1,7 +1,7 @@
|
|||
DOKKU_HOST := dokku@dev.lookingfora.name
|
||||
SHELL := /bin/bash
|
||||
DOCKER_IMAGE_NAME ?= bornholm/hydra-passwordless
|
||||
DOCKER_IMAGE_TAG ?= latest
|
||||
DOCKER_IMAGE_TAG ?= $(shell date +%Y%m%d%H%M)
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 go build -v -o bin/server ./cmd/server
|
||||
|
@ -85,8 +85,10 @@ docker-run:
|
|||
|
||||
docker-release: docker-build
|
||||
docker image tag hydra-passwordless:latest $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
|
||||
docker image tag hydra-passwordless:latest $(DOCKER_IMAGE_NAME):latest
|
||||
docker login
|
||||
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
|
||||
docker push $(DOCKER_IMAGE_NAME):latest
|
||||
|
||||
clean:
|
||||
rm -rf release
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<title>{{block "title" . -}}{{- end}}</title>
|
||||
{{- block "head_style" . -}}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css" />
|
||||
<link rel="stylesheet" href="/css/style.css" />
|
||||
<link rel="stylesheet" href="{{ .BaseURL }}/css/style.css" />
|
||||
{{end}}
|
||||
{{- block "head_script" . -}}{{end}}
|
||||
</head>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
Autorisez vous l'application à utiliser ces informations vous concernant ?
|
||||
</p>
|
||||
<div class="box">
|
||||
<form action="/consent" method="POST">
|
||||
<form action="{{ .BaseURL }}/consent" method="POST">
|
||||
{{range .RequestedScope}}
|
||||
<div class="">
|
||||
<label class="checkbox">
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
Veuillez entrer votre adresse courriel.
|
||||
</p>
|
||||
<div class="box">
|
||||
<form action="/login" method="POST">
|
||||
<form action="{{ .BaseURL }}/login" method="POST">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input class="input is-large" type="email"
|
||||
|
|
|
@ -18,13 +18,12 @@ import (
|
|||
)
|
||||
|
||||
type SendConfirmationEmailRequest struct {
|
||||
Email string
|
||||
Challenge string
|
||||
DefaultScheme string
|
||||
DefaultAddress string
|
||||
RememberMe bool
|
||||
ClientName string
|
||||
ClientURI string
|
||||
Email string
|
||||
Challenge string
|
||||
BaseURL string
|
||||
RememberMe bool
|
||||
ClientName string
|
||||
ClientURI string
|
||||
}
|
||||
|
||||
func HandleSendConfirmationEmailRequest(ctx context.Context, cmd cqrs.Command) error {
|
||||
|
@ -56,21 +55,7 @@ func HandleSendConfirmationEmailRequest(ctx context.Context, cmd cqrs.Command) e
|
|||
return errors.Wrap(err, "could not generate jwt")
|
||||
}
|
||||
|
||||
address := req.DefaultAddress
|
||||
if conf.HTTP.PublicAddress != "" {
|
||||
address = conf.HTTP.PublicAddress
|
||||
}
|
||||
|
||||
scheme := req.DefaultScheme
|
||||
if scheme == "" {
|
||||
scheme = "http:"
|
||||
}
|
||||
|
||||
if conf.HTTP.PublicScheme != "" {
|
||||
scheme = conf.HTTP.PublicScheme
|
||||
}
|
||||
|
||||
verificationLink := fmt.Sprintf("%s//%s/verify?token=%s", scheme, address, token)
|
||||
verificationLink := fmt.Sprintf("%s/verify?token=%s", req.BaseURL, token)
|
||||
|
||||
data := template.Data{
|
||||
"ClientName": req.ClientName,
|
||||
|
|
|
@ -42,12 +42,10 @@ type HTTPConfig struct {
|
|||
CookieEncryptionKey string `yaml:"cookieEncryptionKey" env:"HTTP_COOKIE_ENCRYPTION_KEY"`
|
||||
TokenSigningKey string `yaml:"tokenSigningKey" env:"HTTP_TOKEN_SIGNING_KEY"`
|
||||
TokenEncryptionKey string `yaml:"tokenEncryptionKey" env:"HTTP_TOKEN_ENCRYPTION_KEY"`
|
||||
BasePublicURL string `yaml:"basePublicUrl" env:"HTTP_BASE_PUBLIC_URL"`
|
||||
BaseURL string `yaml:"basePublicUrl" env:"HTTP_BASE_URL"`
|
||||
CookieMaxAge int `yaml:"cookieMaxAge" env:"HTTP_COOKIE_MAX_AGE"`
|
||||
TemplateDir string `yaml:"templateDir" env:"HTTP_TEMPLATE_DIR"`
|
||||
PublicDir string `yaml:"publicDir" env:"HTTP_PUBLIC_DIR"`
|
||||
PublicAddress string `yaml:"publicAddress" env:"HTTP_PUBLIC_ADDRESS"`
|
||||
PublicScheme string `yaml:"publicScheme" env:"HTTP_PUBLIC_SCHEME"`
|
||||
}
|
||||
|
||||
type SMTPConfig struct {
|
||||
|
@ -100,8 +98,7 @@ func NewDefault() *Config {
|
|||
CookieMaxAge: int((time.Hour * 1).Seconds()), // 1 hour
|
||||
TemplateDir: "template",
|
||||
PublicDir: "public",
|
||||
PublicAddress: "",
|
||||
PublicScheme: "",
|
||||
BaseURL: "/",
|
||||
},
|
||||
SMTP: SMTPConfig{
|
||||
Host: "localhost",
|
||||
|
|
|
@ -2,9 +2,12 @@ package route
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
"gitlab.com/wpetit/goweb/service"
|
||||
"gitlab.com/wpetit/goweb/service/template"
|
||||
"gitlab.com/wpetit/goweb/template/html"
|
||||
)
|
||||
|
@ -14,8 +17,8 @@ func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Da
|
|||
data, err := template.Extend(data,
|
||||
html.WithFlashes(w, r, ctn),
|
||||
template.WithBuildInfo(w, r, ctn),
|
||||
withBaseURL(w, r, ctn),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not extend template data"))
|
||||
}
|
||||
|
@ -23,6 +26,19 @@ func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Da
|
|||
return data
|
||||
}
|
||||
|
||||
func withBaseURL(w http.ResponseWriter, r *http.Request, ctn *service.Container) template.DataExtFunc {
|
||||
return func(data template.Data) (template.Data, error) {
|
||||
conf, err := config.From(ctn)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
data["BaseURL"] = strings.TrimSuffix(conf.HTTP.BaseURL, "/")
|
||||
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func renderErrorPage(w http.ResponseWriter, r *http.Request, statusCode int, title, description string) error {
|
||||
ctn := container.Must(r.Context())
|
||||
tmpl := template.Must(ctn)
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
netMail "net/mail"
|
||||
"strings"
|
||||
|
||||
"forge.cadoles.com/wpetit/hydra-passwordless/internal/command"
|
||||
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
|
||||
"forge.cadoles.com/wpetit/hydra-passwordless/internal/hydra"
|
||||
"github.com/gorilla/csrf"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -81,6 +84,7 @@ func handleLoginForm(w http.ResponseWriter, r *http.Request) {
|
|||
tmpl := template.Must(ctn)
|
||||
hydr := hydra.Must(ctn)
|
||||
bus := cqrs.Must(ctn)
|
||||
conf := config.Must(ctn)
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
|
@ -143,14 +147,21 @@ func handleLoginForm(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var baseURL string
|
||||
|
||||
if conf.HTTP.BaseURL != "" {
|
||||
baseURL = strings.TrimSuffix(conf.HTTP.BaseURL, "/")
|
||||
} else {
|
||||
baseURL = fmt.Sprintf("%s//%s", r.Host, r.URL.Scheme)
|
||||
}
|
||||
|
||||
cmd := &command.SendConfirmationEmailRequest{
|
||||
Email: email,
|
||||
Challenge: challenge,
|
||||
DefaultScheme: r.URL.Scheme,
|
||||
DefaultAddress: r.Host,
|
||||
RememberMe: rememberMe == "on",
|
||||
ClientName: res.Client.ClientName,
|
||||
ClientURI: res.Client.ClientURI,
|
||||
Email: email,
|
||||
Challenge: challenge,
|
||||
BaseURL: baseURL,
|
||||
RememberMe: rememberMe == "on",
|
||||
ClientName: res.Client.ClientName,
|
||||
ClientURI: res.Client.ClientURI,
|
||||
}
|
||||
if _, err := bus.Exec(ctx, cmd); err != nil {
|
||||
panic(errors.Wrap(err, "could not execute command"))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1.14 AS build
|
||||
FROM golang:1.17 AS build
|
||||
|
||||
ARG HTTP_PROXY=
|
||||
ARG HTTPS_PROXY=
|
||||
|
|
Loading…
Reference in New Issue