From c07557be026cbef2e5373a37da54b12b01b5d098 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 16 Mar 2022 10:55:29 +0100 Subject: [PATCH] feat: build the redirect after a successful login with AuthCallbackURL function (#164) --- pkg/op/op.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/op/op.go b/pkg/op/op.go index 1c233ea..e910bf6 100644 --- a/pkg/op/op.go +++ b/pkg/op/op.go @@ -19,6 +19,7 @@ import ( const ( healthEndpoint = "/healthz" readinessEndpoint = "/ready" + authCallbackPathSuffix = "/callback" defaultAuthorizationEndpoint = "authorize" defaultTokenEndpoint = "oauth/token" defaultIntrospectEndpoint = "oauth/introspect" @@ -72,7 +73,7 @@ func CreateRouter(o OpenIDProvider, interceptors ...HttpInterceptor) *mux.Router router.HandleFunc(readinessEndpoint, readyHandler(o.Probes())) router.HandleFunc(oidc.DiscoveryEndpoint, discoveryHandler(o, o.Signer())) router.Handle(o.AuthorizationEndpoint().Relative(), intercept(authorizeHandler(o))) - router.NewRoute().Path(o.AuthorizationEndpoint().Relative()+"/callback").Queries("id", "{id}").Handler(intercept(authorizeCallbackHandler(o))) + router.NewRoute().Path(authCallbackPath(o)).Queries("id", "{id}").Handler(intercept(authorizeCallbackHandler(o))) router.Handle(o.TokenEndpoint().Relative(), intercept(tokenHandler(o))) router.HandleFunc(o.IntrospectionEndpoint().Relative(), introspectionHandler(o)) router.HandleFunc(o.UserinfoEndpoint().Relative(), userinfoHandler(o)) @@ -82,6 +83,17 @@ func CreateRouter(o OpenIDProvider, interceptors ...HttpInterceptor) *mux.Router return router } +//AuthCallbackURL builds the url for the redirect (with the requestID) after a successful login +func AuthCallbackURL(o OpenIDProvider) func(string) string { + return func(requestID string) string { + return o.AuthorizationEndpoint().Absolute(o.Issuer()) + authCallbackPathSuffix + "?id=" + requestID + } +} + +func authCallbackPath(o OpenIDProvider) string { + return o.AuthorizationEndpoint().Relative() + authCallbackPathSuffix +} + type Config struct { Issuer string CryptoKey [32]byte