Repository: ory/kratos
Pull request #207 (2020-01-30 16:16:33)

Update quickstart


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1015b305a..fee1f63ff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
 
 **Implemented enhancements:**
 
+- Rework public and admin fetch strategy [\#203](https://github.com/ory/kratos/pull/203) ([aeneasr](https://github.com/aeneasr))
 - Update HTTP routes for a consistent API naming [\#199](https://github.com/ory/kratos/pull/199) ([aeneasr](https://github.com/aeneasr))
 
 **Fixed bugs:**
@@ -39,6 +40,7 @@
 
 **Merged pull requests:**
 
+- ci: Bump sdk orb [\#206](https://github.com/ory/kratos/pull/206) ([aeneasr](https://github.com/aeneasr))
 - ss/profile: Use request ID as query param everywhere [\#202](https://github.com/ory/kratos/pull/202) ([aeneasr](https://github.com/aeneasr))
 
 ## [v0.0.1-alpha.9](https://github.com/ory/kratos/tree/v0.0.1-alpha.9) (2020-01-29)
diff --git a/cmd/daemon/serve.go b/cmd/daemon/serve.go
index 54c31c4ba..ee713676f 100644
--- a/cmd/daemon/serve.go
+++ b/cmd/daemon/serve.go
@@ -35,11 +35,10 @@ func servePublic(d driver.Driver, wg *sync.WaitGroup, cmd *cobra.Command, args [
 	telemetry(cmd, n, d)
 
 	router := x.NewRouterPublic()
-	admin := x.NewRouterAdmin()
-	r.LoginHandler().RegisterPublicRoutes(router, admin)
-	r.RegistrationHandler().RegisterRoutes(router, admin)
+	r.LoginHandler().RegisterPublicRoutes(router)
+	r.RegistrationHandler().RegisterPublicRoutes(router)
 	r.LogoutHandler().RegisterPublicRoutes(router)
-	r.ProfileManagementHandler().RegisterPublicRoutes(router, admin)
+	r.ProfileManagementHandler().RegisterPublicRoutes(router)
 	r.LoginStrategies().RegisterPublicRoutes(router)
 	r.RegistrationStrategies().RegisterPublicRoutes(router)
 	r.SessionHandler().RegisterPublicRoutes(router)
@@ -80,6 +79,9 @@ func serveAdmin(d driver.Driver, wg *sync.WaitGroup, cmd *cobra.Command, args []
 	r := d.Registry()
 
 	router := x.NewRouterAdmin()
+	r.RegistrationHandler().RegisterAdminRoutes(router)
+	r.LoginHandler().RegisterAdminRoutes(router)
+	r.ProfileManagementHandler().RegisterAdminRoutes(router)
 	r.IdentityHandler().RegisterAdminRoutes(router)
 	r.SessionHandler().RegisterAdminRoutes(router)
 	r.HealthHandler().SetRoutes(router.Router, false)
diff --git a/contrib/quickstart/oathkeeper/access-rules.yml b/contrib/quickstart/oathkeeper/access-rules.yml
index a35510059..74c0d176e 100644
--- a/contrib/quickstart/oathkeeper/access-rules.yml
+++ b/contrib/quickstart/oathkeeper/access-rules.yml
@@ -57,4 +57,4 @@
   errors:
     - handler: redirect
       config:
-        to: http://127.0.0.1:4455/.ory/kratos/public/auth/browser/login
+        to: http://127.0.0.1:4455/auth/login
diff --git a/quickstart.yml b/quickstart.yml
index 77dd52e63..875722ba3 100644
--- a/quickstart.yml
+++ b/quickstart.yml
@@ -34,6 +34,7 @@ services:
     environment:
       - PORT=4435
       - KRATOS_PUBLIC_URL=http://kratos:4433/
+      - KRATOS_ADMIN_URL=http://kratos:4434/
       - KRATOS_BROWSER_URL=http://127.0.0.1:4455/.ory/kratos/public
       - JWKS_URL=http://oathkeeper:4456/.well-known/jwks.json
     networks:
diff --git a/selfservice/flow/login/handler.go b/selfservice/flow/login/handler.go
index 694ea7c2d..3ea0b5e66 100644
--- a/selfservice/flow/login/handler.go
+++ b/selfservice/flow/login/handler.go
@@ -49,9 +49,12 @@ func (h *Handler) WithTokenGenerator(f func(r *http.Request) string) {
 	h.csrf = f
 }
 
-func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic, admin *x.RouterAdmin) {
+func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic) {
 	public.GET(BrowserLoginPath, h.d.SessionHandler().IsNotAuthenticated(h.initLoginRequest, session.RedirectOnAuthenticated(h.c)))
 	public.GET(BrowserLoginRequestsPath, h.publicFetchLoginRequest)
+}
+
+func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin) {
 	admin.GET(BrowserLoginRequestsPath, h.adminFetchLoginRequest)
 }
 
diff --git a/selfservice/flow/profile/handler.go b/selfservice/flow/profile/handler.go
index 7ea8999a5..ab3fc8db0 100644
--- a/selfservice/flow/profile/handler.go
+++ b/selfservice/flow/profile/handler.go
@@ -66,12 +66,14 @@ func NewHandler(d handlerDependencies, c configuration.Provider) *Handler {
 	return &Handler{d: d, c: c, csrf: nosurf.Token}
 }
 
-func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic, admin *x.RouterAdmin) {
+func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic) {
 	redirect := session.RedirectOnUnauthenticated(h.c.LoginURL().String())
 	public.GET(PublicProfileManagementPath, h.d.SessionHandler().IsAuthenticated(h.initUpdateProfile, redirect))
 	public.GET(PublicProfileManagementRequestPath, h.d.SessionHandler().IsAuthenticated(h.publicFetchUpdateProfileRequest, redirect))
 	public.POST(PublicProfileManagementUpdatePath, h.d.SessionHandler().IsAuthenticated(h.completeProfileManagementFlow, redirect))
+}
 
+func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin) {
 	admin.GET(AdminBrowserProfileRequestPath, h.adminFetchUpdateProfileRequest)
 }
 
diff --git a/selfservice/flow/registration/handler.go b/selfservice/flow/registration/handler.go
index 98828a6c4..05fa3be70 100644
--- a/selfservice/flow/registration/handler.go
+++ b/selfservice/flow/registration/handler.go
@@ -49,9 +49,12 @@ func (h *Handler) WithTokenGenerator(f func(r *http.Request) string) {
 	h.csrf = f
 }
 
-func (h *Handler) RegisterRoutes(public *x.RouterPublic, admin *x.RouterAdmin) {
+func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic) {
 	public.GET(BrowserRegistrationPath, h.d.SessionHandler().IsNotAuthenticated(h.initRegistrationRequest, session.RedirectOnAuthenticated(h.c)))
 	public.GET(BrowserRegistrationRequestsPath, h.publicFetchRegistrationRequest)
+}
+
+func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin) {
 	admin.GET(BrowserRegistrationRequestsPath, h.adminFetchRegistrationRequest)
 }
 


Test patch:
diff --git a/selfservice/flow/login/handler_test.go b/selfservice/flow/login/handler_test.go
index 782f62f9b..b9f8f6b3b 100644
--- a/selfservice/flow/login/handler_test.go
+++ b/selfservice/flow/login/handler_test.go
@@ -34,7 +34,8 @@ func TestEnsureSessionRedirect(t *testing.T) {
 
 	router := x.NewRouterPublic()
 	admin := x.NewRouterAdmin()
-	reg.LoginHandler().RegisterPublicRoutes(router, admin)
+	reg.LoginHandler().RegisterPublicRoutes(router)
+	reg.LoginHandler().RegisterAdminRoutes(admin)
 	reg.LoginStrategies().RegisterPublicRoutes(router)
 	ts := httptest.NewServer(router)
 	defer ts.Close()
@@ -71,7 +72,8 @@ func TestLoginHandler(t *testing.T) {
 	public, admin := func() (*httptest.Server, *httptest.Server) {
 		public := x.NewRouterPublic()
 		admin := x.NewRouterAdmin()
-		reg.LoginHandler().RegisterPublicRoutes(public, admin)
+		reg.LoginHandler().RegisterPublicRoutes(public)
+		reg.LoginHandler().RegisterAdminRoutes(admin)
 		reg.LoginStrategies().RegisterPublicRoutes(public)
 		return httptest.NewServer(nosurf.New(public)), httptest.NewServer(admin)
 	}()
diff --git a/selfservice/flow/profile/handler_test.go b/selfservice/flow/profile/handler_test.go
index 0dd1bd9b3..b90a9e5a4 100644
--- a/selfservice/flow/profile/handler_test.go
+++ b/selfservice/flow/profile/handler_test.go
@@ -87,7 +87,8 @@ func TestUpdateProfile(t *testing.T) {
 	publicTS, adminTS := func() (*httptest.Server, *httptest.Server) {
 		router := x.NewRouterPublic()
 		admin := x.NewRouterAdmin()
-		reg.ProfileManagementHandler().RegisterPublicRoutes(router, admin)
+		reg.ProfileManagementHandler().RegisterPublicRoutes(router)
+		reg.ProfileManagementHandler().RegisterAdminRoutes(admin)
 		route, _ := session.MockSessionCreateHandlerWithIdentity(t, reg, primaryIdentity)
 		router.GET("/setSession", route)
 
@@ -138,7 +139,8 @@ func TestUpdateProfile(t *testing.T) {
 
 	t.Run("description=call endpoints", func(t *testing.T) {
 		pr, ar := x.NewRouterPublic(), x.NewRouterAdmin()
-		reg.ProfileManagementHandler().RegisterPublicRoutes(pr, ar)
+		reg.ProfileManagementHandler().RegisterPublicRoutes(pr)
+		reg.ProfileManagementHandler().RegisterAdminRoutes(ar)
 
 		adminTS, publicTS := httptest.NewServer(ar), httptest.NewServer(pr)
 		defer adminTS.Close()
diff --git a/selfservice/flow/registration/handler_test.go b/selfservice/flow/registration/handler_test.go
index 8c5db6eae..b4ad97762 100644
--- a/selfservice/flow/registration/handler_test.go
+++ b/selfservice/flow/registration/handler_test.go
@@ -33,7 +33,7 @@ func TestEnsureSessionRedirect(t *testing.T) {
 	_, reg := internal.NewRegistryDefault(t)
 
 	router := x.NewRouterPublic()
-	reg.RegistrationHandler().RegisterRoutes(router, x.NewRouterAdmin())
+	reg.RegistrationHandler().RegisterPublicRoutes(router)
 	reg.RegistrationStrategies().RegisterPublicRoutes(router)
 	ts := httptest.NewServer(router)
 	defer ts.Close()
@@ -70,7 +70,8 @@ func TestRegistrationHandler(t *testing.T) {
 	public, admin := func() (*httptest.Server, *httptest.Server) {
 		public := x.NewRouterPublic()
 		admin := x.NewRouterAdmin()
-		reg.RegistrationHandler().RegisterRoutes(public, admin)
+		reg.RegistrationHandler().RegisterPublicRoutes(public)
+		reg.RegistrationHandler().RegisterAdminRoutes(admin)
 		reg.RegistrationStrategies().RegisterPublicRoutes(public)
 		return httptest.NewServer(nosurf.New(public)), httptest.NewServer(admin)
 	}()
diff --git a/selfservice/strategy/oidc/strategy_test.go b/selfservice/strategy/oidc/strategy_test.go
index 9eb636d2b..df6143632 100644
--- a/selfservice/strategy/oidc/strategy_test.go
+++ b/selfservice/strategy/oidc/strategy_test.go
@@ -125,13 +125,15 @@ func TestStrategy(t *testing.T) {
 
 	public := x.NewRouterPublic()
 	admin := x.NewRouterAdmin()
-	reg.LoginHandler().RegisterPublicRoutes(public, admin)
+	reg.LoginHandler().RegisterPublicRoutes(public)
+	reg.LoginHandler().RegisterAdminRoutes(admin)
 	reg.LoginHandler().WithTokenGenerator(func(r *http.Request) string {
 		return "nosurf"
 	})
 	reg.LoginStrategies().RegisterPublicRoutes(public)
 	reg.RegistrationStrategies().RegisterPublicRoutes(public)
-	reg.RegistrationHandler().RegisterRoutes(public, admin)
+	reg.RegistrationHandler().RegisterPublicRoutes(public)
+	reg.RegistrationHandler().RegisterAdminRoutes(admin)
 	reg.RegistrationHandler().WithTokenGenerator(func(r *http.Request) string {
 		return "nosurf"
 	})
diff --git a/selfservice/strategy/password/login_test.go b/selfservice/strategy/password/login_test.go
index f7d6bcb8f..edd1b43e4 100644
--- a/selfservice/strategy/password/login_test.go
+++ b/selfservice/strategy/password/login_test.go
@@ -346,7 +346,8 @@ func TestLogin(t *testing.T) {
 
 			router := x.NewRouterPublic()
 			admin := x.NewRouterAdmin()
-			reg.LoginHandler().RegisterPublicRoutes(router, admin)
+			reg.LoginHandler().RegisterPublicRoutes(router)
+			reg.LoginHandler().RegisterAdminRoutes(admin)
 			s.RegisterLoginRoutes(router)
 			ts := httptest.NewServer(router)
 			defer ts.Close()
diff --git a/selfservice/strategy/password/registration_test.go b/selfservice/strategy/password/registration_test.go
index 84eb53dac..c212cae22 100644
--- a/selfservice/strategy/password/registration_test.go
+++ b/selfservice/strategy/password/registration_test.go
@@ -66,7 +66,8 @@ func TestRegistration(t *testing.T) {
 		router := x.NewRouterPublic()
 		admin := x.NewRouterAdmin()
 		reg.RegistrationStrategies().RegisterPublicRoutes(router)
-		reg.RegistrationHandler().RegisterRoutes(router, admin)
+		reg.RegistrationHandler().RegisterPublicRoutes(router)
+		reg.RegistrationHandler().RegisterAdminRoutes(admin)
 		ts := httptest.NewServer(router)
 		defer ts.Close()