GithubHelp home page GithubHelp logo

Authenticated Request about go-http-auth HOT 5 CLOSED

abbot avatar abbot commented on August 18, 2024
Authenticated Request

from go-http-auth.

Comments (5)

ralfr avatar ralfr commented on August 18, 2024

I guess you try to address my problem with the wrapped.go example, however, I'm getting the following error:

the runtime process gave a bad HTTP response: ''

from go-http-auth.

abbot avatar abbot commented on August 18, 2024

This was a design decision. http.Request does not have a good place to pass authentication information, so it can't be used, and this also does not allow to use http.HandlerFunc with authenticated requests passing authentication information. If you are not interested in authentication information, use JustCheck wrapper as shown in wrapped.go example. Please reopen this ticket if wrapped.go example does not work as expected.

from go-http-auth.

bamarni avatar bamarni commented on August 18, 2024

Would you accept a PR with a handler similar to JustCheck except that it takes a standard http handler func? It should be possible to put the username in the request context since go 1.7 (https://golang.org/doc/go1.7#context).

from go-http-auth.

abbot avatar abbot commented on August 18, 2024

I guess, it would be a variation of https://github.com/abbot/go-http-auth/blob/master/examples/context.go, right?

Something like

func authenticatedHandler(a auth.AuthenticatorInterface, h http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        h.ServeHTTP(w, r.WithContext(a.NewContext(r.Context(), r)))
    })
}

(didn't actually test this code)

Can you point at your code?

from go-http-auth.

bamarni avatar bamarni commented on August 18, 2024

I haven't implemented it yet, but your snippet looks fine. Do you suggest that we create this handler func ourself in our projects, or that this package provides it as a helper?

It seems very similar to JustCheck excepts it sets it in the request context rather than a HTTP header.

from go-http-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.