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

Need ability to add middleware handler functions for extension #15

Open
jmrodri opened this issue Mar 6, 2018 · 1 comment
Open

Need ability to add middleware handler functions for extension #15

jmrodri opened this issue Mar 6, 2018 · 1 comment

Comments

@jmrodri
Copy link
Contributor

jmrodri commented Mar 6, 2018

There are times we will want to add an auth handler or other http handler middleware to allow for authentication before accessing the broker.

https://github.com/openshift/ansible-service-broker/blob/master/pkg/handler/handler.go#L196

// authHandler - does the authentication for the routes
func authHandler(h http.Handler, providers []auth.Provider) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

        var principalFound error
        for _, provider := range providers {
            principal, err := provider.GetPrincipal(r)
            if principal != nil {
                log.Debug("We found one. HOORAY!")
                // we found our principal, stop looking
                break
            }
            if err != nil {
                principalFound = err
            }
        }
        // if we went through the providers and found no principals. We will
        // have found an error
        if principalFound != nil {
            log.Debug("no principal found")
            writeResponse(w, http.StatusUnauthorized, broker.ErrorResponse{Description: principalFound.Error()})
            return
        }

        h.ServeHTTP(w, r)
    })
}
@pmorie
Copy link
Owner

pmorie commented Mar 7, 2018

Seems like a very good idea

jboyd01 pushed a commit to jboyd01/osb-broker-lib that referenced this issue Apr 17, 2018
Reorganize so that a single package contains all the user's code
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

No branches or pull requests

2 participants