Skip to content

Commit 36f5721

Browse files
Display a redirecting page when browsers on android visit a completed web session
ref DEV-2484 ref DEV-2215
2 parents 3dab2db + f9370d6 commit 36f5721

File tree

122 files changed

+2138
-1546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2138
-1546
lines changed

.make-lint-translation-keys-expect

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ resources/authgear/templates/en/web/authflowv2/forgot_password.html:103:30: temp
2828
resources/authgear/templates/en/web/authflowv2/forgot_password.html:159:26: template translation is forbidden: `__forgot_password_alternative`
2929
resources/authgear/templates/en/web/authflowv2/layout.html:5:14: template translation is forbidden: `widget`
3030
resources/authgear/templates/en/web/authflowv2/login.html:253:37: translation key not defined: "%s-icon"
31-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_email.html:57:44: translation key not defined: "v2.page.settings-identity-list-email.default.provider.%s"
32-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:56:32: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
33-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:107:35: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
34-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_phone.html:57:44: translation key not defined: "v2.page.settings-identity-list-phone.default.provider.%s"
31+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_email.html:58:44: translation key not defined: "v2.page.settings-identity-list-email.default.provider.%s"
32+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:57:32: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
33+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:108:35: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
34+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_phone.html:58:44: translation key not defined: "v2.page.settings-identity-list-phone.default.provider.%s"
3535
resources/authgear/templates/en/web/authflowv2/settings_layout.html:3:14: template translation is forbidden: `widget`
36-
resources/authgear/templates/en/web/authflowv2/settings_mfa.html:69:44: translation key not defined: "/settings/mfa/create_oob_otp_%s"
37-
resources/authgear/templates/en/web/authflowv2/settings_oob_otp.html:77:31: translation key not defined: "/settings/mfa/create_oob_otp_%s"
38-
resources/authgear/templates/en/web/authflowv2/settings_profile.html:139:22: translation key not defined: "custom-attribute-label-%s"
39-
resources/authgear/templates/en/web/authflowv2/settings_profile.html:140:20: invalid translation key: "$labelKey"
40-
resources/authgear/templates/en/web/authflowv2/settings_profile.html:144:21: invalid translation key: "$labelKey"
41-
resources/authgear/templates/en/web/authflowv2/settings_profile.html:208:22: invalid translation key: "$label"
36+
resources/authgear/templates/en/web/authflowv2/settings_mfa.html:70:44: translation key not defined: "/settings/mfa/create_oob_otp_%s"
37+
resources/authgear/templates/en/web/authflowv2/settings_oob_otp.html:78:31: translation key not defined: "/settings/mfa/create_oob_otp_%s"
38+
resources/authgear/templates/en/web/authflowv2/settings_profile.html:140:22: translation key not defined: "custom-attribute-label-%s"
39+
resources/authgear/templates/en/web/authflowv2/settings_profile.html:141:20: invalid translation key: "$labelKey"
40+
resources/authgear/templates/en/web/authflowv2/settings_profile.html:145:21: invalid translation key: "$labelKey"
41+
resources/authgear/templates/en/web/authflowv2/settings_profile.html:209:22: invalid translation key: "$label"
4242
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:6:18: translation key not defined: "custom-attribute-label-%s"
4343
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:7:16: invalid translation key: "$labelKey"
4444
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:11:17: invalid translation key: "$labelKey"
45-
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:103:30: translation key not defined: "custom-attribute-enum-label-%s-%s"
46-
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:104:28: invalid translation key: "$enum_label_key"
47-
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:107:28: invalid translation key: "$enum_label_key"
48-
resources/authgear/templates/en/web/authflowv2/settings_sessions.html:46:29: translation key not defined: "__settings_session_item_description"
45+
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:104:30: translation key not defined: "custom-attribute-enum-label-%s-%s"
46+
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:105:28: invalid translation key: "$enum_label_key"
47+
resources/authgear/templates/en/web/authflowv2/settings_profile_edit_custom.html:108:28: invalid translation key: "$enum_label_key"
48+
resources/authgear/templates/en/web/authflowv2/settings_sessions.html:47:29: translation key not defined: "__settings_session_item_description"
4949
resources/authgear/templates/en/web/authflowv2/signup.html:93:26: translation key not defined: "v2.page.signup-login.continue.subtitle-%v"
5050
resources/authgear/templates/en/web/authflowv2/signup.html:102:26: translation key not defined: "v2.page.signup.continue.subtitle-%v"
5151
resources/authgear/templates/en/web/authflowv2/signup.html:276:35: translation key not defined: "%s-icon"

.vettedpositions

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
/pkg/auth/handler/webapp/auth_entry_point_middleware.go:31:31: requestcontext
4141
/pkg/auth/handler/webapp/auth_entry_point_middleware.go:32:35: requestcontext
4242
/pkg/auth/handler/webapp/authflow_change_password.go:96:26: requestcontext
43-
/pkg/auth/handler/webapp/authflow_controller.go:1001:19: requestcontext
44-
/pkg/auth/handler/webapp/authflow_controller.go:979:30: requestcontext
45-
/pkg/auth/handler/webapp/authflow_controller.go:984:24: requestcontext
46-
/pkg/auth/handler/webapp/authflow_controller.go:992:19: requestcontext
43+
/pkg/auth/handler/webapp/authflow_controller.go:989:30: requestcontext
44+
/pkg/auth/handler/webapp/authflow_controller.go:994:24: requestcontext
45+
/pkg/auth/handler/webapp/authflow_controller.go:1002:19: requestcontext
46+
/pkg/auth/handler/webapp/authflow_controller.go:1011:19: requestcontext
4747
/pkg/auth/handler/webapp/authflow_create_password.go:132:26: requestcontext
4848
/pkg/auth/handler/webapp/authflow_enter_oob_otp.go:156:26: requestcontext
4949
/pkg/auth/handler/webapp/authflow_enter_password.go:138:26: requestcontext
@@ -101,9 +101,7 @@
101101
/pkg/auth/handler/webapp/authflowv2/settings_change_password.go:70:30: requestcontext
102102
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:76:30: requestcontext
103103
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:78:39: requestcontext
104-
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:80:34: requestcontext
105104
/pkg/auth/handler/webapp/authflowv2/settings_delete_account_success.go:54:30: requestcontext
106-
/pkg/auth/handler/webapp/authflowv2/settings_delete_account_success.go:56:34: requestcontext
107105
/pkg/auth/handler/webapp/authflowv2/settings_identity_add_email.go:73:30: requestcontext
108106
/pkg/auth/handler/webapp/authflowv2/settings_identity_add_phone.go:81:30: requestcontext
109107
/pkg/auth/handler/webapp/authflowv2/settings_identity_change_primary_email.go:105:30: requestcontext
@@ -233,15 +231,15 @@
233231
/pkg/auth/handler/webapp/verify_identity.go:161:27: requestcontext
234232
/pkg/auth/handler/webapp/verify_identity_success.go:42:27: requestcontext
235233
/pkg/auth/handler/webapp/verify_login_link.go:92:27: requestcontext
236-
/pkg/auth/handler/webapp/viewmodels/base.go:213:32: requestcontext
237-
/pkg/auth/handler/webapp/viewmodels/base.go:228:35: requestcontext
238-
/pkg/auth/handler/webapp/viewmodels/base.go:230:57: requestcontext
239-
/pkg/auth/handler/webapp/viewmodels/base.go:282:38: requestcontext
240-
/pkg/auth/handler/webapp/viewmodels/base.go:288:24: requestcontext
241-
/pkg/auth/handler/webapp/viewmodels/base.go:300:43: requestcontext
242-
/pkg/auth/handler/webapp/viewmodels/base.go:376:47: requestcontext
243-
/pkg/auth/handler/webapp/viewmodels/base.go:381:28: requestcontext
244-
/pkg/auth/handler/webapp/viewmodels/base.go:394:33: requestcontext
234+
/pkg/auth/handler/webapp/viewmodels/base.go:217:32: requestcontext
235+
/pkg/auth/handler/webapp/viewmodels/base.go:232:35: requestcontext
236+
/pkg/auth/handler/webapp/viewmodels/base.go:234:57: requestcontext
237+
/pkg/auth/handler/webapp/viewmodels/base.go:286:38: requestcontext
238+
/pkg/auth/handler/webapp/viewmodels/base.go:292:24: requestcontext
239+
/pkg/auth/handler/webapp/viewmodels/base.go:304:43: requestcontext
240+
/pkg/auth/handler/webapp/viewmodels/base.go:381:47: requestcontext
241+
/pkg/auth/handler/webapp/viewmodels/base.go:386:28: requestcontext
242+
/pkg/auth/handler/webapp/viewmodels/base.go:399:33: requestcontext
245243
/pkg/auth/handler/webapp/websocket.go:45:25: requestcontext
246244
/pkg/auth/handler/webapp/websocket.go:56:25: requestcontext
247245
/pkg/auth/handler/webapp/websocket.go:80:30: requestcontext
1.98 KB
Binary file not shown.
Binary file not shown.

pkg/auth/handler/webapp/alternatives.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type CreateAuthenticatorPhoneOTPNode interface {
2828
// nolint: gocognit
2929
func handleAlternativeSteps(ctrl *Controller) {
3030
ctrl.PostAction("choose_step", func(ctx context.Context) (err error) {
31-
session, err := ctrl.InteractionSession(ctx)
31+
session, err := ctrl.GetWebappSession(ctx)
3232
if err != nil {
3333
return err
3434
}

pkg/auth/handler/webapp/authflow_controller.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,16 @@ func (c *AuthflowController) HandleStartOfFlow(
202202
handleWithScreen(screen)
203203
}
204204

205+
func (c *AuthflowController) isExpectedWebSessionError(err error) bool {
206+
return apierrors.IsKind(err, webapp.WebUIInvalidSession) || apierrors.IsKind(err, webapp.WebUISessionCompleted)
207+
}
208+
205209
func (c *AuthflowController) HandleOAuthCallback(ctx context.Context, w http.ResponseWriter, r *http.Request, callbackResponse AuthflowOAuthCallbackResponse) {
206210
state := callbackResponse.State
207211

208212
s, err := c.Sessions.Get(ctx, state.WebSessionID)
209213
if err != nil {
210-
if !apierrors.IsKind(err, webapp.WebUIInvalidSession) {
214+
if !c.isExpectedWebSessionError(err) {
211215
c.Logger.WithError(err).Errorf("failed to get web session")
212216
}
213217
c.renderError(ctx, w, r, err)
@@ -309,7 +313,7 @@ func (c *AuthflowController) HandleStep(ctx context.Context, w http.ResponseWrit
309313

310314
s, err := c.getWebSession(ctx)
311315
if err != nil {
312-
if !apierrors.IsKind(err, webapp.WebUIInvalidSession) {
316+
if !c.isExpectedWebSessionError(err) {
313317
c.Logger.WithError(err).Errorf("failed to get web session")
314318
}
315319
c.renderError(ctx, w, r, err)
@@ -341,7 +345,7 @@ func (c *AuthflowController) HandleWithoutFlow(ctx context.Context, w http.Respo
341345
var session *webapp.Session
342346
s, err := c.getWebSession(ctx)
343347
if err != nil {
344-
if !apierrors.IsKind(err, webapp.WebUIInvalidSession) {
348+
if !c.isExpectedWebSessionError(err) {
345349
c.Logger.WithError(err).Errorf("failed to get web session")
346350
}
347351
} else {
@@ -368,21 +372,27 @@ func (c *AuthflowController) getWebSession(ctx context.Context) (*webapp.Session
368372
if s == nil {
369373
return nil, webapp.ErrSessionNotFound
370374
}
375+
if s.IsCompleted {
376+
return nil, webapp.ErrSessionCompleted
377+
}
371378
return s, nil
372379
}
373380

374381
func (c *AuthflowController) getOrCreateWebSession(ctx context.Context, w http.ResponseWriter, r *http.Request, opts webapp.SessionOptions) (*webapp.Session, error) {
375382
now := c.Clock.NowUTC()
376-
s := webapp.GetSession(ctx)
377-
if s != nil {
383+
s, err := c.getWebSession(ctx)
384+
if err == nil && s != nil {
378385
return s, nil
379386
}
387+
if !errors.Is(err, webapp.ErrSessionNotFound) {
388+
return nil, err
389+
}
380390

381391
o := opts
382392
o.UpdatedAt = now
383393

384394
s = webapp.NewSession(o)
385-
err := c.Sessions.Create(ctx, s)
395+
err = c.Sessions.Create(ctx, s)
386396
if err != nil {
387397
return nil, err
388398
}
@@ -1129,16 +1139,17 @@ func (c *AuthflowController) finishSession(
11291139
case authflow.FlowTypeSignupLogin:
11301140
fallthrough
11311141
case authflow.FlowTypeReauth:
1132-
// Forget the session.
1133-
err := c.Sessions.Delete(ctx, s.ID)
1142+
// Mark the current session as completed,
1143+
// so that user will see a completed screen if trying to back to the previous steps
1144+
s.IsCompleted = true
1145+
err = c.Sessions.Update(ctx, s)
11341146
if err != nil {
11351147
return err
11361148
}
11371149
// Marked signed up in cookie after authorization.
11381150
// When user visit auth ui root "/", redirect user to "/login" if
11391151
// cookie exists
11401152
result.Cookies = append(result.Cookies, c.Cookies.ValueCookie(c.SignedUpCookie.Def, "true"))
1141-
result.Cookies = append(result.Cookies, c.Cookies.ClearCookie(c.SessionCookie.Def))
11421153
// Reset visitor ID.
11431154
result.Cookies = append(result.Cookies, c.Cookies.ClearCookie(webapp.VisitorIDCookieDef))
11441155
default:

pkg/auth/handler/webapp/authflowv2/select_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (h *AuthflowV2SelectAccountHandler) ServeHTTP(w http.ResponseWriter, r *htt
123123
ctrl.BeforeHandle(func(ctx context.Context) error {
124124

125125
// Ensure webapp session exist
126-
ws, err := ctrl.InteractionSession(ctx)
126+
ws, err := ctrl.GetWebappSession(ctx)
127127
if err != nil {
128128
return err
129129
}

pkg/auth/handler/webapp/authflowv2/settings_change_password.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (h *AuthflowV2SettingsChangePasswordHandler) ServeHTTP(w http.ResponseWrite
6969
}
7070
defer ctrl.ServeWithoutDBTx(r.Context())
7171

72-
ctrl.Get(func(ctx context.Context) error {
72+
ctrl.GetWithSettingsActionWebSession(r, func(ctx context.Context, _ *webapp.Session) error {
7373
data, err := h.GetData(r, w)
7474
if err != nil {
7575
return err
@@ -80,7 +80,7 @@ func (h *AuthflowV2SettingsChangePasswordHandler) ServeHTTP(w http.ResponseWrite
8080
return nil
8181
})
8282

83-
ctrl.PostAction("", func(ctx context.Context) error {
83+
ctrl.PostActionWithSettingsActionWebSession("", r, func(ctx context.Context, webappSession *webapp.Session) error {
8484
err := AuthflowV2SettingsChangePasswordSchema.Validator().ValidateValue(handlerwebapp.FormToJSON(r.Form))
8585
if err != nil {
8686
return err
@@ -96,29 +96,29 @@ func (h *AuthflowV2SettingsChangePasswordHandler) ServeHTTP(w http.ResponseWrite
9696
}
9797

9898
s := session.GetSession(ctx)
99-
webappSession := webapp.GetSession(ctx)
100-
var oAuthSessionID string
101-
redirectURI := SettingsV2RouteSettings
102-
if webappSession != nil {
103-
oAuthSessionID = webappSession.OAuthSessionID
104-
redirectURI = webappSession.RedirectURI
105-
}
10699

107100
input := &accountmanagement.ChangePrimaryPasswordInput{
108-
OAuthSessionID: oAuthSessionID,
109-
RedirectURI: redirectURI,
110-
OldPassword: oldPassword,
111-
NewPassword: newPassword,
101+
OldPassword: oldPassword,
102+
NewPassword: newPassword,
112103
}
113104

114-
changePasswordOutput, err := h.AccountManagementService.ChangePrimaryPassword(ctx, s, input)
105+
err = h.AccountManagementService.ChangePrimaryPassword(ctx, s, input)
115106
if err != nil {
116107
return err
117108
}
118109

110+
if ctrl.IsInSettingsAction(s, webappSession) {
111+
settingsActionResult, err := ctrl.FinishSettingsActionWithResult(ctx, s, webappSession)
112+
if err != nil {
113+
return err
114+
}
115+
settingsActionResult.WriteResponse(w, r)
116+
return nil
117+
}
118+
119119
result := webapp.Result{
120-
RedirectURI: changePasswordOutput.RedirectURI,
121120
NavigationAction: webapp.NavigationActionRedirect,
121+
RedirectURI: SettingsV2RouteSettings,
122122
}
123123
result.WriteResponse(w, r)
124124
return nil

pkg/auth/handler/webapp/authflowv2/settings_delete_account.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ func (h *AuthflowV2SettingsDeleteAccountHandler) ServeHTTP(w http.ResponseWriter
7777

7878
currentSession := session.GetSession(r.Context())
7979
redirectURI := "/settings/delete_account/success"
80-
webSession := webapp.GetSession(r.Context())
8180

82-
ctrl.Get(func(ctx context.Context) error {
81+
ctrl.GetWithSettingsActionWebSession(r, func(ctx context.Context, _ *webapp.Session) error {
8382
var data map[string]interface{}
8483
err := h.Database.WithTx(ctx, func(ctx context.Context) error {
8584
data, err = h.GetData(ctx, r, w)
@@ -93,8 +92,7 @@ func (h *AuthflowV2SettingsDeleteAccountHandler) ServeHTTP(w http.ResponseWriter
9392

9493
return nil
9594
})
96-
97-
ctrl.PostAction("delete", func(ctx context.Context) error {
95+
ctrl.PostActionWithSettingsActionWebSession("delete", r, func(ctx context.Context, webappSession *webapp.Session) error {
9896
confirmation := r.Form.Get("delete")
9997
isConfirmed := confirmation == "DELETE"
10098
if !isConfirmed {
@@ -108,10 +106,10 @@ func (h *AuthflowV2SettingsDeleteAccountHandler) ServeHTTP(w http.ResponseWriter
108106
return err
109107
}
110108

111-
if ctrl.IsInSettingsAction(currentSession, webSession) {
109+
if ctrl.IsInSettingsAction(currentSession, webappSession) {
112110
// delete account triggered by sdk via settings action
113111
// handle settings action result here
114-
err = ctrl.FinishSettingsAction(ctx, currentSession, webSession)
112+
err = ctrl.FinishSettingsAction(ctx, currentSession, webappSession)
115113
if err != nil {
116114
return err
117115
}

pkg/auth/handler/webapp/authflowv2/settings_delete_account_success.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ func (h *AuthflowV2SettingsDeleteAccountSuccessHandler) ServeHTTP(w http.Respons
5353
}
5454
defer ctrl.ServeWithoutDBTx(r.Context())
5555

56-
webSession := webapp.GetSession(r.Context())
57-
58-
ctrl.Get(func(ctx context.Context) error {
56+
ctrl.GetWithSettingsActionWebSession(r, func(ctx context.Context, _ *webapp.Session) error {
5957
data, err := h.GetData(r, w)
6058
if err != nil {
6159
return nil
@@ -64,9 +62,9 @@ func (h *AuthflowV2SettingsDeleteAccountSuccessHandler) ServeHTTP(w http.Respons
6462
return nil
6563
})
6664

67-
ctrl.PostAction("", func(ctx context.Context) error {
65+
ctrl.PostActionWithSettingsActionWebSession("", r, func(ctx context.Context, webSession *webapp.Session) error {
6866
redirectURI := "/login"
69-
settingsActionResult, ok, err := ctrl.GetSettingsActionResult(ctx, webSession)
67+
settingsActionResult, ok, err := ctrl.CreateSettingsActionResult(ctx, webSession)
7068
if err != nil {
7169
return err
7270
}

0 commit comments

Comments
 (0)