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 a POST request handler to the direct provider #57

Merged
merged 1 commit into from Jun 23, 2020

Conversation

o1egl
Copy link
Contributor

@o1egl o1egl commented Jun 22, 2020

In some case it's required to send user provided input data in POST request. This PR adds application/x-www-form-urlencoded and application/json encoded body processors to the direct handler.

@o1egl o1egl requested a review from umputun as a code owner June 22, 2020 10:45
@o1egl o1egl force-pushed the post_direct_handler branch 2 times, most recently from beb9c52 to 80355b0 Compare June 22, 2020 11:30
@coveralls
Copy link

coveralls commented Jun 22, 2020

Pull Request Test Coverage Report for Build 144177369

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 94.388%

Totals Coverage Status
Change from base Build 140224538: 0.0%
Covered Lines: 185
Relevant Lines: 196

💛 - Coveralls

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

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

good idea, thx.

A few minor suggestions. And in addition, the readme section about direct auth should be updated accordingly

if contentType == "application/json" {
var credentials Credentials
if err := json.NewDecoder(r.Body).Decode(&credentials); err != nil {
return Credentials{}, fmt.Errorf("failed to parse request body: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

pkg/errors already in the list of deps and used in other places. i.e. errors.Wrap(err, "failed to parse request body") will be consistent

@@ -13,6 +16,13 @@ import (
"github.com/go-pkgz/auth/token"
)

const (
// MaxHTTPBodySize defines max http body size
MaxHTTPBodySize = megabyte
Copy link
Member

Choose a reason for hiding this comment

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

MaxHTTPBodySize = 1024*1024 will be easier to read

@@ -37,21 +47,48 @@ func (f CredCheckerFunc) Check(user, password string) (ok bool, err error) {
return f(user, password)
}

// Credentials holds user credentials
type Credentials struct {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this struct supposed to be exposed. If so, making it credentials makes more sense

func (p DirectHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
user, password := r.URL.Query().Get("user"), r.URL.Query().Get("passwd")
aud := r.URL.Query().Get("aud")
if r.Body != nil {
Copy link
Member

Choose a reason for hiding this comment

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

probably, moving this body wrapping to getCredentials will make this part closer to the consumer and more readable

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

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

LGTM, thx.

@umputun umputun merged commit afcc185 into go-pkgz:master Jun 23, 2020
@umputun umputun mentioned this pull request Jan 3, 2021
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.

None yet

3 participants