-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from formancehq/feature/handle-strip-prefix
feat: refactor to properly handle urls prefix stripped.
- Loading branch information
Showing
10 changed files
with
48 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package routing | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
package api | ||
|
||
import ( | ||
"net/url" | ||
"context" | ||
"net/http" | ||
|
||
"github.com/formancehq/auth/pkg/api/routing" | ||
"github.com/gorilla/mux" | ||
sharedhealth "github.com/numary/go-libs/sharedhealth/pkg" | ||
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" | ||
"go.uber.org/fx" | ||
) | ||
|
||
func Module(addr string, baseUrl *url.URL) fx.Option { | ||
func CreateRootRouter(healthController *sharedhealth.HealthController) *mux.Router { | ||
rootRouter := mux.NewRouter() | ||
rootRouter.Use(otelmux.Middleware("auth")) | ||
rootRouter.Use(func(handler http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
handler.ServeHTTP(w, r) | ||
}) | ||
}) | ||
rootRouter.Path("/_healthcheck").HandlerFunc(healthController.Check) | ||
|
||
return rootRouter | ||
} | ||
|
||
func Module(addr string) fx.Option { | ||
return fx.Options( | ||
sharedhealth.ProvideHealthCheck(delegatedOIDCServerAvailability), | ||
routing.Module(addr, baseUrl), | ||
sharedhealth.Module(), | ||
fx.Provide(func(healthController *sharedhealth.HealthController) *mux.Router { | ||
return CreateRootRouter(healthController) | ||
}), | ||
fx.Invoke(func(lc fx.Lifecycle, router *mux.Router, healthController *sharedhealth.HealthController) { | ||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
return StartServer(ctx, addr, router) | ||
}, | ||
}) | ||
}), | ||
fx.Invoke( | ||
fx.Annotate(addClientRoutes, fx.ParamTags(``, `name:"prefixedRouter"`)), | ||
fx.Annotate(addScopeRoutes, fx.ParamTags(``, `name:"prefixedRouter"`)), | ||
fx.Annotate(addUserRoutes, fx.ParamTags(``, `name:"prefixedRouter"`)), | ||
addClientRoutes, | ||
addScopeRoutes, | ||
addUserRoutes, | ||
), | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package routing | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
package oidc | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/zitadel/oidc/pkg/client/rp" | ||
"github.com/zitadel/oidc/pkg/op" | ||
) | ||
|
||
func AddRoutes(router *mux.Router, provider op.OpenIDProvider, storage Storage, relyingParty rp.RelyingParty, baseUrl *url.URL) { | ||
func AddRoutes(router *mux.Router, provider op.OpenIDProvider, storage Storage, relyingParty rp.RelyingParty) { | ||
router.NewRoute().Path("/authorize/callback").Queries("code", "{code}"). | ||
Handler(authorizeCallbackHandler(provider, storage, relyingParty)) | ||
router.NewRoute().Path("/authorize/callback").Queries("error", "{error}"). | ||
Handler(authorizeErrorHandler()) | ||
router.PathPrefix("/").Handler(http.StripPrefix(baseUrl.Path, provider.HttpHandler())) | ||
router.PathPrefix("/").Handler(provider.HttpHandler()) | ||
} |