Update thermokarst/jwt

This commit is contained in:
Matthew Dillon 2015-07-17 16:35:44 -08:00
parent 763c1f77d1
commit fb5985ded6
2 changed files with 15 additions and 3 deletions

2
Godeps/Godeps.json generated
View file

@ -47,7 +47,7 @@
},
{
"ImportPath": "github.com/thermokarst/jwt",
"Rev": "e04139dd784854614da87333bcef5f9faeeabc21"
"Rev": "7752009bbb5cea39ab392a846c467eab4b98478f"
},
{
"ImportPath": "golang.org/x/crypto/bcrypt",

View file

@ -11,6 +11,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"strings"
)
@ -98,11 +99,22 @@ func New(c *Config) (*Middleware, error) {
// to have it's own verification/validation protocol.
func (m *Middleware) Secure(h http.Handler, v VerifyClaimsFunc) http.Handler {
secureHandler := func(w http.ResponseWriter, r *http.Request) *jwtError {
var token string
authHeader := r.Header.Get("Authorization")
if authHeader == "" {
return &jwtError{status: http.StatusUnauthorized, err: ErrMissingToken}
queryParam := r.FormValue("token")
if queryParam == "" {
return &jwtError{status: http.StatusUnauthorized, err: ErrMissingToken}
}
var err error
token, err = url.QueryUnescape(queryParam)
if err != nil {
return &jwtError{status: http.StatusUnauthorized, err: ErrMalformedToken}
}
} else {
token = strings.Split(authHeader, " ")[1]
}
token := strings.Split(authHeader, " ")[1]
tokenParts := strings.Split(token, ".")
if len(tokenParts) != 3 {
return &jwtError{status: http.StatusUnauthorized, err: ErrMalformedToken}