go get github.com/auth0/go-jwt-middleware
Add the following lines to your base code
// JSON response function
func respondJson(text string, w http.ResponseWriter) {
response := Response{text}
jsonResponse, err := json.Marshal(response)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(jsonResponse)
}
// Regular HTTP HandlerFunc
func SecuredPingHandler(w http.ResponseWriter, r *http.Request) {
respondJson("All good. You only get this message if you're authenticated", w)
}
// Negroni sample
r := mux.NewRouter()
r.Handle("/secured/ping", negroni.New(
negroni.HandlerFunc(jwtMiddleware.HandlerWithNext),
negroni.Wrap(http.HandlerFunc(SecuredPingHandler)),
))
http.Handle("/", r)
http.ListenAndServe(":3001", nil)
// net/http sample
app := jwtMiddleware.Handler(SecuredPingHandler)
http.ListenAndServe("0.0.0.0:3001", app)
Auth0 is the easiest way for developers to integrate enterprise-grade authentication and identity management to any app.
SOC 2, HIPAA/BAA, EU/US Privacy Shield Framework, Open ID Certified.
Learn MoreContinuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.
Learn MoreContinuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.
Learn MoreUptime time in 3 different regions.
Learn MoreDeploy On-Premises or on Cloud on your data center or Auth0’s one.
Learn MoreAuthenticate PHP API with Active Directory / LDAP
Authenticate Spring Security 4 Java API with Active Directory / LDAP
Authenticate iOS Swift - Facebook Login with Active Directory / LDAP
Authenticate Vue with Active Directory / LDAP
Authenticate Device Authorization Flow with Active Directory / LDAP