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

Add VerifyPassword to API #1486

Merged
merged 1 commit into from
Jul 22, 2019
Merged

Add VerifyPassword to API #1486

merged 1 commit into from
Jul 22, 2019

Conversation

AlbanSeurat
Copy link
Contributor

It takes in an email and plain text password to verify. If it fails to find a password stored for email, it returns not_found. If it finds the password hash stored but that hash doesn't match the password passed via the API, it returns verified = false, else it returns verified = true.

Re-open with fix to make it possible to merge

@AlbanSeurat
Copy link
Contributor Author

AlbanSeurat commented Jul 13, 2019

I have corrected the PR from tylerclocke from previous comments and feedbacks from the team.
Any chance to merge that code in master ?

@srenatus
Copy link
Contributor

I'd be curious about your use case -- how do you intend to make use of this? 😃

@AlbanSeurat
Copy link
Contributor Author

We are using it to check our user’s password (from a back-end service) before calling updatePassword.
We are using dex as central repository for our users.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Sorry, more comments 😅 But thanks for picking this up!

While I'd personally appreciate some sort of GRPC connector to store users myself (in our backend service) and have dex provide the login fields for that, this is a decent approach, I think.

@@ -254,6 +254,36 @@ func (d dexAPI) ListPasswords(ctx context.Context, req *api.ListPasswordReq) (*a

}

func (d dexAPI) VerifyPassword(ctx context.Context, req *api.VerifyPasswordReq) (*api.VerifyPasswordResp, error) {
if req.Email == "" {
return nil, errors.New("no email supplied")
Copy link
Contributor

Choose a reason for hiding this comment

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

This being GRPC, can we return status.Error(codes.InvalidArguments, "no email supplied") or something like that? errors.New(), or, any error would translate to codes.Internal or codes.Unknown, can't remember.

Copy link
Contributor Author

@AlbanSeurat AlbanSeurat Jul 19, 2019

Choose a reason for hiding this comment

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

I can change the error returned, but that will not be consistent with the rest of errors returned by the other functions. Do you want me to do it anyway ? and you will have some other tasks where you will change the other functions ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll deal with the others. 😃 You know what, you're correct, this is fine, let's keep them as-is and we can update all the errors in one go later.

return nil, fmt.Errorf("verify password: %v", err)
}

if err := bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the err interesting? If so, we might log it. If not, we could do

if bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)) != nil {

instead. Or even

verified := bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)) == nil
return &api.VerifyPasswordResp{Verified: verified}, 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.

I will add some log

@AlbanSeurat
Copy link
Contributor Author

I have updated the branch in regards to some comments - adding some logs.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

🎉 Thank you! I'll get this merged on Monday if there's no objections 😃

@AlbanSeurat
Copy link
Contributor Author

Great ! Thanks

@srenatus
Copy link
Contributor

@AlbanSeurat One small thing that kept me from merging this: you haven't added your name as author anywhere. I suppose it would make sense to amend this PR's commit and add

Co-authored-by: YOUREMAIL

so that github will pick it up as your contribution, too, properly. 😃

It takes in an email and plain text password to verify. If it fails to find a password stored for email, it returns not_found. If it finds the password hash stored but that hash doesn't match the password passed via the API, it returns verified = false, else it returns verified = true.

Co-authored-by: Alban Seurat <[email protected]>
@AlbanSeurat
Copy link
Contributor Author

@AlbanSeurat One small thing that kept me from merging this: you haven't added your name as author anywhere. I suppose it would make sense to amend this PR's commit and add

Co-authored-by: YOUREMAIL

so that github will pick it up as your contribution, too, properly. 😃

Done

@srenatus srenatus merged commit 6379403 into dexidp:master Jul 22, 2019
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
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