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

feat(selfservice/login): enable reauthentication functionality #248

Merged
merged 15 commits into from
Feb 28, 2020

Conversation

zepatrik
Copy link
Member

@zepatrik zepatrik commented Feb 14, 2020

Related issue

contributes to #243

Proposed changes

Checklist

  • I have read the contributing guidelines
  • I have read the security policy
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact security@ory.sh) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)
  • I have documented my changes in the developer guide (if appropriate)

Further comments

# Conflicts:
#	selfservice/flow/login/handler_test.go
#	selfservice/strategy/password/login_test.go
@zepatrik zepatrik marked this pull request as ready for review February 17, 2020 11:49
@zepatrik zepatrik requested a review from aeneasr February 17, 2020 11:49
selfservice/flow/login/handler.go Outdated Show resolved Hide resolved
# Conflicts:
#	persistence/sql/persister_login.go
@zepatrik zepatrik requested a review from aeneasr February 18, 2020 11:59
@@ -110,6 +111,12 @@ func (h *Handler) NewLoginRequest(w http.ResponseWriter, r *http.Request, redir
// 500: genericError
func (h *Handler) initLoginRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if err := h.NewLoginRequest(w, r, func(a *Request) (string, error) {
// we assume an error means the user has no session
if _, err := h.d.SessionManager().FetchFromRequest(r.Context(), w, r); err == nil && r.URL.Query().Get("prompt") == "true" {
Copy link
Member

Choose a reason for hiding this comment

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

The && doesn't make sense here. Please add a failing test case first.

}
t.Run("does set reauth flag on authenticated request", func(t *testing.T) {
rid := x.NewUUID()
req := x.NewTestHTTPRequest(t, "GET", ts.URL+login.BrowserLoginPath, nil)
Copy link
Member

Choose a reason for hiding this comment

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

This is missing ?prompt=true

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

gotcha 👍

{"GET", login.BrowserLoginPath},
t.Run("does not set reauth flag on unauthenticated request", func(t *testing.T) {
c := ts.Client()
res, err := c.Get(ts.URL + login.BrowserLoginPath)
Copy link
Member

Choose a reason for hiding this comment

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

This should work for both prompt=true and prompt=false and no prompt

@@ -18,7 +18,8 @@ type (
RequestPersister interface {
CreateLoginRequest(context.Context, *Request) error
GetLoginRequest(context.Context, uuid.UUID) (*Request, error)
UpdateLoginRequest(context.Context, uuid.UUID, identity.CredentialsType, *RequestMethod) error
UpdateLoginRequestMethod(context.Context, uuid.UUID, identity.CredentialsType, *RequestMethod) error
UpdateLoginRequestReauth(ctx context.Context, id uuid.UUID, reauth bool) error
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a one-way method (reauth is false by default and can only be set to true) wouldn't it make sense to name this something like MarkLoginRequestForced? Alternatively UpdateLoginRequest(context.Context, *Request).

@@ -0,0 +1 @@
add_column("selfservice_login_requests", "is_reauthentication", "bool", {default: false})
Copy link
Member

Choose a reason for hiding this comment

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

I would like to rename this to forced or, alternatively prompt although I think that forced is clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 forced

@@ -61,6 +65,9 @@ type Request struct {

// CSRFToken contains the anti-csrf token associated with this request.
CSRFToken string `json:"-" db:"csrf_token"`

// IsReauthentication stores whether this login request is a reauthenication request.
IsReauthentication bool `json:"is_reauthentication" db:"is_reauthentication"`
Copy link
Member

Choose a reason for hiding this comment

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

I think forced is shorter and as concise :)

}, public)
c, err := p.OAuth2(context.TODO())
require.NoError(t, err)
return c.AuthCodeURL("state", p.AddAuthCodeURLOptions(r)...)
Copy link
Member

Choose a reason for hiding this comment

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

I would rename this function to p.AuthCodeURLOptions because you are returning the options, not adding it to something.

@@ -456,4 +459,41 @@ func TestStrategy(t *testing.T) {
aue(t, res, body, "an account with the same identifier (email, phone, username, ...) exists already")
})
})

Copy link
Member

Choose a reason for hiding this comment

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

Nice test cases :)

identity.PrivilegedPoolProvider
password.HashProvider
}
func TestLoginNew(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactoring - this looks so much more readable :)

@zepatrik zepatrik requested a review from aeneasr February 19, 2020 12:12
@zepatrik
Copy link
Member Author

ready for review @aeneasr

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Good job!

@aeneasr aeneasr merged commit 344fc9c into master Feb 28, 2020
@zepatrik zepatrik deleted the add-reauth-endpoint branch March 23, 2020 18:47
@aeneasr aeneasr mentioned this pull request Apr 7, 2020
2 tasks
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.

2 participants