Update thermokarst/jwt
This commit is contained in:
parent
763c1f77d1
commit
fb5985ded6
2 changed files with 15 additions and 3 deletions
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
|
@ -47,7 +47,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/thermokarst/jwt",
|
"ImportPath": "github.com/thermokarst/jwt",
|
||||||
"Rev": "e04139dd784854614da87333bcef5f9faeeabc21"
|
"Rev": "7752009bbb5cea39ab392a846c467eab4b98478f"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "golang.org/x/crypto/bcrypt",
|
"ImportPath": "golang.org/x/crypto/bcrypt",
|
||||||
|
|
14
Godeps/_workspace/src/github.com/thermokarst/jwt/jwt.go
generated
vendored
14
Godeps/_workspace/src/github.com/thermokarst/jwt/jwt.go
generated
vendored
|
@ -11,6 +11,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -98,11 +99,22 @@ func New(c *Config) (*Middleware, error) {
|
||||||
// to have it's own verification/validation protocol.
|
// to have it's own verification/validation protocol.
|
||||||
func (m *Middleware) Secure(h http.Handler, v VerifyClaimsFunc) http.Handler {
|
func (m *Middleware) Secure(h http.Handler, v VerifyClaimsFunc) http.Handler {
|
||||||
secureHandler := func(w http.ResponseWriter, r *http.Request) *jwtError {
|
secureHandler := func(w http.ResponseWriter, r *http.Request) *jwtError {
|
||||||
|
var token string
|
||||||
|
|
||||||
authHeader := r.Header.Get("Authorization")
|
authHeader := r.Header.Get("Authorization")
|
||||||
if authHeader == "" {
|
if authHeader == "" {
|
||||||
|
queryParam := r.FormValue("token")
|
||||||
|
if queryParam == "" {
|
||||||
return &jwtError{status: http.StatusUnauthorized, err: ErrMissingToken}
|
return &jwtError{status: http.StatusUnauthorized, err: ErrMissingToken}
|
||||||
}
|
}
|
||||||
token := strings.Split(authHeader, " ")[1]
|
var err error
|
||||||
|
token, err = url.QueryUnescape(queryParam)
|
||||||
|
if err != nil {
|
||||||
|
return &jwtError{status: http.StatusUnauthorized, err: ErrMalformedToken}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
token = strings.Split(authHeader, " ")[1]
|
||||||
|
}
|
||||||
tokenParts := strings.Split(token, ".")
|
tokenParts := strings.Split(token, ".")
|
||||||
if len(tokenParts) != 3 {
|
if len(tokenParts) != 3 {
|
||||||
return &jwtError{status: http.StatusUnauthorized, err: ErrMalformedToken}
|
return &jwtError{status: http.StatusUnauthorized, err: ErrMalformedToken}
|
||||||
|
|
Reference in a new issue