Skip to content

Commit f9d5152

Browse files
Support add login id setting actions
ref DEV-2411
2 parents 4c7c1d8 + b27ad72 commit f9d5152

19 files changed

+1772
-1158
lines changed

.vettedpositions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
/pkg/auth/handler/webapp/authflowv2/settings_advanced.go:46:30: requestcontext
100100
/pkg/auth/handler/webapp/authflowv2/settings_biometric.go:94:30: requestcontext
101101
/pkg/auth/handler/webapp/authflowv2/settings_change_password.go:70:30: requestcontext
102-
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:78:30: requestcontext
103-
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:80:39: requestcontext
104-
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:82:34: requestcontext
102+
/pkg/auth/handler/webapp/authflowv2/settings_delete_account.go:76:30: requestcontext
103+
/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
105105
/pkg/auth/handler/webapp/authflowv2/settings_delete_account_success.go:54:30: requestcontext
106106
/pkg/auth/handler/webapp/authflowv2/settings_delete_account_success.go:56:34: requestcontext
107107
/pkg/auth/handler/webapp/authflowv2/settings_identity_add_email.go:73:30: requestcontext

authui/src/authflowv2/components/otp-input.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
.otp-input__digits-container {
7777
@apply absolute;
7878
@apply inset-0;
79-
@apply flex;
79+
@apply flex justify-center;
8080
@apply items-stretch;
8181
@apply gap-x-[var(--otp-input\_\_spacing)];
8282
@apply pointer-events-none;

authui/src/authflowv2/components/widget.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@
9999
@apply widget-content-item__px--settings;
100100
}
101101

102+
@media (min-width: theme("screens.tablet")) {
103+
.widget-content__alert--settings {
104+
@apply widget-content-item__mx--settings;
105+
}
106+
}
102107
.widget-content__alert--settings {
103-
@apply widget-content-item__mx--settings;
108+
@apply mx-6;
104109
}
105110
}

pkg/auth/deps.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ var DependencySet = wire.NewSet(
105105
wire.Bind(new(webapp.SessionMiddlewareSAMLUIInfoResolver), new(*samlsession.UIService)),
106106

107107
wire.Bind(new(webapp.UIInfoResolver), new(*authenticationinfo.UIService)),
108+
wire.Bind(new(handlerwebapp.ControllerUIInfoResolver), new(*authenticationinfo.UIService)),
108109
wire.Bind(new(handlerwebapp.SettingsDeleteAccountSuccessUIInfoResolver), new(*authenticationinfo.UIService)),
110+
109111
wire.Bind(new(handlerwebapp.SelectAccountAuthenticationInfoService), new(*authenticationinfo.StoreRedis)),
112+
wire.Bind(new(handlerwebapp.ControllerAuthenticationInfoService), new(*authenticationinfo.StoreRedis)),
110113
wire.Bind(new(handlerwebappauthflowv2.SelectAccountAuthenticationInfoService), new(*authenticationinfo.StoreRedis)),
111114
wire.Bind(new(handlerwebapp.SettingsDeleteAccountSuccessAuthenticationInfoService), new(*authenticationinfo.StoreRedis)),
112115
wire.Bind(new(handlerwebapp.SettingsDeleteAccountAuthenticationInfoService), new(*authenticationinfo.StoreRedis)),
116+
113117
wire.Bind(new(handlerwebapp.SetupTOTPEndpointsProvider), new(*endpoints.Endpoints)),
114118
wire.Bind(new(handlerwebapp.OAuthEntrypointEndpointsProvider), new(*endpoints.Endpoints)),
115119
wire.Bind(new(handlerwebapp.ConfirmTerminateOtherSessionsEndpointsProvider), new(*endpoints.Endpoints)),
@@ -189,6 +193,7 @@ var DependencySet = wire.NewSet(
189193
handlerwebapp.DependencySet,
190194
wire.Bind(new(handlerwebapp.AuthflowControllerOAuthClientResolver), new(*oauthclient.Resolver)),
191195
wire.Bind(new(handlerwebapp.AuthflowControllerSessionStore), new(*webapp.SessionStoreRedis)),
196+
wire.Bind(new(handlerwebapp.ControllerSessionStore), new(*webapp.SessionStoreRedis)),
192197
wire.Bind(new(handlerwebapp.SettingsDeleteAccountSessionStore), new(*webapp.SessionStoreRedis)),
193198
wire.Bind(new(handlerwebapp.SettingsAuthenticatorService), new(*authenticatorservice.Service)),
194199
wire.Bind(new(handlerwebapp.SettingsMFAService), new(*mfa.Service)),
@@ -200,6 +205,7 @@ var DependencySet = wire.NewSet(
200205
wire.Bind(new(handlerwebapp.SettingsProfileEditCustomAttrsService), new(*featurecustomattrs.Service)),
201206
wire.Bind(new(handlerwebapp.SettingsDeleteAccountUserService), new(*facade.UserFacade)),
202207
wire.Bind(new(handlerwebapp.SettingsDeleteAccountOAuthSessionService), new(*oauthsession.StoreRedis)),
208+
wire.Bind(new(handlerwebapp.ControllerOAuthSessionService), new(*oauthsession.StoreRedis)),
203209
wire.Bind(new(handlerwebapp.SettingsEndpointsProvider), new(*endpoints.Endpoints)),
204210
wire.Bind(new(handlerwebapp.SettingsOAuthStateStore), new(*webappoauth.Store)),
205211
wire.Bind(new(handlerwebapp.SettingsAuthorizationService), new(*oauth.AuthorizationService)),

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import (
1010
handlerwebapp "github.com/authgear/authgear-server/pkg/auth/handler/webapp"
1111
"github.com/authgear/authgear-server/pkg/auth/handler/webapp/viewmodels"
1212
"github.com/authgear/authgear-server/pkg/auth/webapp"
13-
"github.com/authgear/authgear-server/pkg/lib/authn/authenticationinfo"
1413
"github.com/authgear/authgear-server/pkg/lib/config"
1514
"github.com/authgear/authgear-server/pkg/lib/infra/db/appdb"
16-
"github.com/authgear/authgear-server/pkg/lib/oauth/oauthsession"
1715
"github.com/authgear/authgear-server/pkg/lib/session"
1816
"github.com/authgear/authgear-server/pkg/lib/successpage"
1917
"github.com/authgear/authgear-server/pkg/util/clock"
@@ -110,28 +108,10 @@ func (h *AuthflowV2SettingsDeleteAccountHandler) ServeHTTP(w http.ResponseWriter
110108
return err
111109
}
112110

113-
if webSession != nil && webSession.OAuthSessionID != "" {
111+
if ctrl.IsInSettingsAction(currentSession, webSession) {
114112
// delete account triggered by sdk via settings action
115113
// handle settings action result here
116-
117-
authInfoEntry := authenticationinfo.NewEntry(currentSession.CreateNewAuthenticationInfoByThisSession(), webSession.OAuthSessionID, "")
118-
err := h.AuthenticationInfoService.Save(ctx, authInfoEntry)
119-
if err != nil {
120-
return err
121-
}
122-
webSession.Extra["authentication_info_id"] = authInfoEntry.ID
123-
err = h.Sessions.Update(ctx, webSession)
124-
if err != nil {
125-
return err
126-
}
127-
128-
entry, err := h.OAuthSessions.Get(ctx, webSession.OAuthSessionID)
129-
if err != nil {
130-
return err
131-
}
132-
133-
entry.T.SettingsActionResult = oauthsession.NewSettingsActionResult()
134-
err = h.OAuthSessions.Save(ctx, entry)
114+
err = ctrl.FinishSettingsAction(ctx, currentSession, webSession)
135115
if err != nil {
136116
return err
137117
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,15 @@ func (h *AuthflowV2SettingsDeleteAccountSuccessHandler) ServeHTTP(w http.Respons
6666

6767
ctrl.PostAction("", func(ctx context.Context) error {
6868
redirectURI := "/login"
69-
if webSession != nil && webSession.RedirectURI != "" {
69+
settingsActionResult, ok, err := ctrl.GetSettingsActionResult(ctx, webSession)
70+
if err != nil {
71+
return err
72+
}
73+
if ok {
7074
// delete account triggered by sdk via settings action
7175
// redirect to oauth callback
72-
redirectURI = webSession.RedirectURI
73-
if authInfoID, ok := webSession.Extra["authentication_info_id"].(string); ok {
74-
authInfo, err := h.AuthenticationInfoService.Get(ctx, authInfoID)
75-
if err != nil {
76-
return err
77-
}
78-
redirectURI = h.UIInfoResolver.SetAuthenticationInfoInQuery(redirectURI, authInfo)
79-
}
76+
settingsActionResult.WriteResponse(w, r)
77+
return nil
8078
}
8179

8280
result := webapp.Result{

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (h *AuthflowV2SettingsIdentityAddEmailHandler) ServeHTTP(w http.ResponseWri
9393
loginID := r.Form.Get("x_login_id")
9494

9595
s := session.GetSession(ctx)
96+
webappSession := webapp.GetSession(ctx)
9697
output, err := h.AccountManagement.StartAddIdentityEmail(ctx, s, &accountmanagement.StartAddIdentityEmailInput{
9798
LoginID: loginID,
9899
LoginIDKey: loginIDKey,
@@ -102,6 +103,7 @@ func (h *AuthflowV2SettingsIdentityAddEmailHandler) ServeHTTP(w http.ResponseWri
102103
}
103104

104105
var redirectURI *url.URL
106+
navivagationAction := webapp.NavigationActionRedirect
105107
if output.NeedVerification {
106108
redirectURI, err = url.Parse(AuthflowV2RouteSettingsIdentityVerifyEmail)
107109
if err != nil {
@@ -113,6 +115,14 @@ func (h *AuthflowV2SettingsIdentityAddEmailHandler) ServeHTTP(w http.ResponseWri
113115
q.Set("q_token", output.Token)
114116

115117
redirectURI.RawQuery = q.Encode()
118+
navivagationAction = webapp.NavigationActionAdvance
119+
} else if ctrl.IsInSettingsAction(s, webappSession) {
120+
settingsActionResult, err := ctrl.FinishSettingsActionWithResult(ctx, s, webappSession)
121+
if err != nil {
122+
return err
123+
}
124+
settingsActionResult.WriteResponse(w, r)
125+
return nil
116126
} else {
117127
redirectURI, err = url.Parse(AuthflowV2RouteSettingsIdentityListEmail)
118128
if err != nil {
@@ -125,7 +135,7 @@ func (h *AuthflowV2SettingsIdentityAddEmailHandler) ServeHTTP(w http.ResponseWri
125135
redirectURI.RawQuery = q.Encode()
126136
}
127137

128-
result := webapp.Result{RedirectURI: redirectURI.String()}
138+
result := webapp.Result{RedirectURI: redirectURI.String(), NavigationAction: navivagationAction}
129139
result.WriteResponse(w, r)
130140
return nil
131141
})

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (h *AuthflowV2SettingsIdentityAddPhoneHandler) ServeHTTP(w http.ResponseWri
102102
loginID := r.Form.Get("x_login_id")
103103

104104
s := session.GetSession(ctx)
105+
webappSession := webapp.GetSession(ctx)
105106
output, err := h.AccountManagement.StartAddIdentityPhone(ctx, s, &accountmanagement.StartAddIdentityPhoneInput{
106107
Channel: channel,
107108
LoginID: loginID,
@@ -120,6 +121,13 @@ func (h *AuthflowV2SettingsIdentityAddPhoneHandler) ServeHTTP(w http.ResponseWri
120121
q.Set("q_token", output.Token)
121122

122123
redirectURI.RawQuery = q.Encode()
124+
} else if ctrl.IsInSettingsAction(s, webappSession) {
125+
settingsActionResult, err := ctrl.FinishSettingsActionWithResult(ctx, s, webappSession)
126+
if err != nil {
127+
return err
128+
}
129+
settingsActionResult.WriteResponse(w, r)
130+
return nil
123131
} else {
124132
redirectURI, err = url.Parse(AuthflowV2RouteSettingsIdentityListPhone)
125133

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,22 @@ func (h *AuthflowV2SettingsIdentityNewUsernameHandler) ServeHTTP(w http.Response
9494
loginIDKey := r.Form.Get("x_login_id_key")
9595
loginID := r.Form.Get("x_login_id")
9696
resolvedSession := session.GetSession(ctx)
97+
webappSession := webapp.GetSession(ctx)
9798
_, err = h.AccountManagement.AddIdentityUsername(ctx, resolvedSession, &accountmanagement.AddIdentityUsernameInput{
9899
LoginIDKey: loginIDKey,
99100
LoginID: loginID,
100101
})
101102
if err != nil {
102103
return err
103104
}
105+
if ctrl.IsInSettingsAction(resolvedSession, webappSession) {
106+
settingsActionResult, err := ctrl.FinishSettingsActionWithResult(ctx, resolvedSession, webappSession)
107+
if err != nil {
108+
return err
109+
}
110+
settingsActionResult.WriteResponse(w, r)
111+
return nil
112+
}
104113

105114
redirectURI, err := url.Parse(AuthflowV2RouteSettingsIdentityListUsername)
106115
if err != nil {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,22 @@ func (h *AuthflowV2SettingsIdentityVerifyEmailHandler) ServeHTTP(w http.Response
153153
code := r.Form.Get("x_code")
154154

155155
s := session.GetSession(ctx)
156+
webappSession := webapp.GetSession(ctx)
156157
_, err = h.AccountManagement.ResumeAddOrUpdateIdentityEmail(ctx, s, tokenString, &accountmanagement.ResumeAddOrUpdateIdentityEmailInput{
157158
LoginIDKey: loginIDKey,
158159
Code: code,
159160
})
160161
if err != nil {
161162
return err
162163
}
164+
if ctrl.IsInSettingsAction(s, webappSession) {
165+
settingsActionResult, err := ctrl.FinishSettingsActionWithResult(ctx, s, webappSession)
166+
if err != nil {
167+
return err
168+
}
169+
settingsActionResult.WriteResponse(w, r)
170+
return nil
171+
}
163172

164173
redirectURI, err := url.Parse(AuthflowV2RouteSettingsIdentityListEmail)
165174
if err != nil {

0 commit comments

Comments
 (0)