Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sdk redirect on settings actions #3827

Merged
merged 14 commits into from
Mar 7, 2024

Conversation

IniZio
Copy link
Contributor

@IniZio IniZio commented Feb 22, 2024

ref #3813

Initially wanted to apply this derive function on all settings sub-pages. However it will be odd to, for example close the webview on remove an identity in /settings/identity page

@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 3 times, most recently from 2cc5ce1 to aa81537 Compare February 23, 2024 06:21
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 4 times, most recently from db703db to 0bf3a3b Compare February 23, 2024 15:20
@louischan-oursky louischan-oursky self-requested a review February 26, 2024 03:50
pkg/auth/handler/webapp/enter_login_id.go Outdated Show resolved Hide resolved
pkg/lib/config/oauth.go Outdated Show resolved Hide resolved
pkg/lib/oauth/handler/resolve.go Outdated Show resolved Hide resolved
pkg/lib/oauth/handler/resolve.go Outdated Show resolved Hide resolved
pkg/lib/oauth/handler/resolve.go Outdated Show resolved Hide resolved
@IniZio
Copy link
Contributor Author

IniZio commented Feb 27, 2024

@tung2744 @louischan-oursky Updated to reflect latest settings action spec, still adding test cases for new response type and grant type 🙏

@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 5 times, most recently from 84afb58 to a55babf Compare February 27, 2024 13:34
@IniZio IniZio changed the title Allow sdk redirect on settings actions [WIP] Allow sdk redirect on settings actions Feb 28, 2024
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch from a55babf to 7dbc9fe Compare February 28, 2024 03:32
@IniZio IniZio changed the title [WIP] Allow sdk redirect on settings actions Allow sdk redirect on settings actions Feb 28, 2024
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 2 times, most recently from efb78ef to 8a6c22a Compare February 28, 2024 04:04
pkg/auth/webapp/service2.go Outdated Show resolved Hide resolved
pkg/auth/webapp/service2.go Outdated Show resolved Hide resolved
pkg/auth/webapp/service2.go Outdated Show resolved Hide resolved
pkg/lib/interaction/nodes/do_ensure_session.go Outdated Show resolved Hide resolved
pkg/lib/interaction/nodes/settings_action_end.go Outdated Show resolved Hide resolved
pkg/lib/oauth/handler/handler_authz.go Outdated Show resolved Hide resolved
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 4 times, most recently from cac1bb5 to 70da13b Compare February 28, 2024 08:52
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch 4 times, most recently from 211c791 to 28cefe1 Compare February 29, 2024 04:38
@IniZio
Copy link
Contributor Author

IniZio commented Feb 29, 2024

Tried to create a stimulus controller that can override history items https://github.com/IniZio/authgear-server/tree/3813-settings-action-redirect-web

The script itself works in other flows, but the consent page will block the history.back(). Tried reauth as well, seems have same issue where pressing back to consent page will show bad request error instead of recovering.

In this pr, I inserted a /settings/close page in history stack instead that redirects user back to original redirect URI.

@IniZio IniZio force-pushed the 3813-settings-action-redirect branch from 6d3832f to ba267df Compare February 29, 2024 05:59
@IniZio
Copy link
Contributor Author

IniZio commented Feb 29, 2024

After discussion, will make web behave similarly as other platforms.

Will guard back-navigation only at consent screen instead. Other screens will still show expired error for now.

Changes:

  • Update consent screen to hold client_id and redirect_uri. If OAuth session is not found, use redirect_uri instead
  • Remove x_authgear_sdk_on_finish and close screen

@IniZio IniZio force-pushed the 3813-settings-action-redirect branch from ba267df to 4e7b9b0 Compare February 29, 2024 16:13
// Do not set anything.
if redirectURI != consentURI {
return redirectURI
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add this?

Copy link
Contributor Author

@IniZio IniZio Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the original code, was removed in a temp commit for an old approach in this pr. New commit adds it back.

&nodes.EdgeDoEnsureSession{
Mode: nodes.EnsureSessionModeNoop,
},
}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add EdgeDoEnsureSession here?

Copy link
Contributor Author

@IniZio IniZio Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it's possible to change password to same as previous value and still return as success. Or should it be treated as fail for settings action?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be a success, but the developer could enable password history check, which should cause the flow to return api error. That should be handled by password policy already.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? EdgeDoEnsureSession should be irrelevant here.

case *nodes.NodeChangePasswordEnd:
  // Password was not changed
  return []interaction.Edge{&nodes.EdgeSettingsActionEnd{}}, nil
case *nodes.NodeDoUpdateAuthenticator:
  return []interaction.Edge{&nodes.EdgeSettingsActionEnd{}}, nil
case *nodes.NodeSettingsActionEnd:
  // Intent is finished.
  return nil, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still need, similar to IntentReauthenticate. Tried removing it results in invalid authentication required

pkg/lib/oauth/handler/handler_authz.go Outdated Show resolved Hide resolved
pkg/lib/oauth/handler/handler_authz.go Outdated Show resolved Hide resolved
@@ -398,7 +428,7 @@ func (h *AuthorizationHandler) doHandle(
// Handle prompt!=none
// We must return here.
if !slice.ContainsString(uiInfo.Prompt, "none") {
endpoint, err := h.UIURLBuilder.Build(client, r, oauthSessionEntry)
endpoint, err := h.UIURLBuilder.BuildAuthenticationURL(client, r, oauthSessionEntry)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will remove parseAuthzRedirectURI, and in here, we will choose between BuildAuthenticationURL and BuildSettingsActionURL. In doing this, we preserve the original code flow, and let the reader to reason the code easier.

pkg/lib/oauth/handler/handler_authz.go Outdated Show resolved Hide resolved
@IniZio IniZio changed the title Allow sdk redirect on settings actions [WIP] Allow sdk redirect on settings actions Mar 4, 2024
@IniZio IniZio force-pushed the 3813-settings-action-redirect branch from 2fbd47d to a82f704 Compare March 4, 2024 07:08
@IniZio IniZio changed the title [WIP] Allow sdk redirect on settings actions Allow sdk redirect on settings actions Mar 4, 2024
&nodes.EdgeDoEnsureSession{
Mode: nodes.EnsureSessionModeNoop,
},
}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? EdgeDoEnsureSession should be irrelevant here.

case *nodes.NodeChangePasswordEnd:
  // Password was not changed
  return []interaction.Edge{&nodes.EdgeSettingsActionEnd{}}, nil
case *nodes.NodeDoUpdateAuthenticator:
  return []interaction.Edge{&nodes.EdgeSettingsActionEnd{}}, nil
case *nodes.NodeSettingsActionEnd:
  // Intent is finished.
  return nil, nil

pkg/lib/oauth/handler/handler_authz.go Outdated Show resolved Hide resolved
@louischan-oursky louischan-oursky force-pushed the 3813-settings-action-redirect branch from d1fe865 to dadf4dd Compare March 6, 2024 07:18
@louischan-oursky louischan-oursky merged commit 09acbe2 into authgear:main Mar 7, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants