Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): allow setting external secure #389

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/authentication/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
sessions Sessions[T]
encryptionKey string
sessionCookieName string
externalSecure bool
}

// Option allows customization of the [Authenticator] such as logging and more.
Expand Down Expand Up @@ -55,6 +56,13 @@
}
}

// WithExternalSecure allows using https redirects when the service is behind a reverse proxy.
func WithExternalSecure[T Ctx](externalSecure bool) Option[T] {
return func(a *Authenticator[T]) {
a.externalSecure = externalSecure

Check warning on line 62 in pkg/authentication/authenticate.go

View check run for this annotation

Codecov / codecov/patch

pkg/authentication/authenticate.go#L60-L62

Added lines #L60 - L62 were not covered by tests
}
}

func New[T Ctx](ctx context.Context, zitadel *zitadel.Zitadel, encryptionKey string, initAuthentication HandlerInitializer[T], options ...Option[T]) (*Authenticator[T], error) {
authN, err := initAuthentication(ctx, zitadel)
if err != nil {
Expand Down Expand Up @@ -143,7 +151,7 @@
a.deleteSessionCookie(w)

proto := "http"
if req.TLS != nil {
if req.TLS != nil || a.externalSecure {

Check warning on line 154 in pkg/authentication/authenticate.go

View check run for this annotation

Codecov / codecov/patch

pkg/authentication/authenticate.go#L154

Added line #L154 was not covered by tests
proto = "https"
}
postLogout := fmt.Sprintf("%s://%s/", proto, req.Host)
Expand Down
Loading