-
Notifications
You must be signed in to change notification settings - Fork 28
/
reauth.go
42 lines (34 loc) · 1.32 KB
/
reauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package authflowv2
import (
"net/http"
handlerwebapp "github.com/authgear/authgear-server/pkg/auth/handler/webapp"
"github.com/authgear/authgear-server/pkg/auth/webapp"
authflow "github.com/authgear/authgear-server/pkg/lib/authenticationflow"
"github.com/authgear/authgear-server/pkg/util/httproute"
)
func ConfigureAuthflowV2ReauthRoute(route httproute.Route) httproute.Route {
return route.
WithMethods("OPTIONS", "GET").
WithPathPattern(AuthflowV2RouteReauth)
}
type AuthflowV2ReauthHandler struct {
Controller *handlerwebapp.AuthflowController
AuthflowNavigator handlerwebapp.AuthflowNavigator
}
func (h *AuthflowV2ReauthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
opts := webapp.SessionOptions{
RedirectURI: h.Controller.RedirectURI(r),
}
var handlers handlerwebapp.AuthflowControllerHandlers
handlers.Get(func(s *webapp.Session, screen *webapp.AuthflowScreenWithFlowResponse) error {
// HandleStartOfFlow used to redirect to the next screen for us.
// But that redirect was removed.
// So we need to redirect here.
// See https://github.com/authgear/authgear-server/issues/3470
result := &webapp.Result{}
screen.Navigate(h.AuthflowNavigator, r, s.ID, result)
result.WriteResponse(w, r)
return nil
})
h.Controller.HandleStartOfFlow(w, r, opts, authflow.FlowTypeReauth, &handlers, nil)
}