revendor with 0.5.2 of auth, with ability to redefine token query
This commit is contained in:
+2
@@ -44,6 +44,7 @@ type Opts struct {
|
||||
JWTHeaderKey string // default "X-JWT"
|
||||
XSRFCookieName string // default "XSRF-TOKEN"
|
||||
XSRFHeaderKey string // default "X-XSRF-TOKEN"
|
||||
JWTQuery string // default "token"
|
||||
|
||||
Issuer string // optional value for iss claim, usually the application name, default "go-pkgz/auth"
|
||||
|
||||
@@ -94,6 +95,7 @@ func NewService(opts Opts) (res *Service) {
|
||||
JWTHeaderKey: opts.JWTHeaderKey,
|
||||
XSRFCookieName: opts.XSRFCookieName,
|
||||
XSRFHeaderKey: opts.XSRFHeaderKey,
|
||||
JWTQuery: opts.JWTQuery,
|
||||
Issuer: res.issuer,
|
||||
AudienceReader: opts.AudienceReader,
|
||||
})
|
||||
|
||||
+4
-5
@@ -4,14 +4,13 @@ package avatar
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"strings"
|
||||
|
||||
// Initializing packages for supporting GIF and JPEG formats.
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/gif" // initializing packages for supporting GIF
|
||||
_ "image/jpeg" // initializing packages for supporting JPEG.
|
||||
_ "image/png" // initializing packages for supporting PNG.
|
||||
"io"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-pkgz/auth/token"
|
||||
)
|
||||
|
||||
+2
-2
@@ -9,10 +9,10 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/go-pkgz/auth/avatar"
|
||||
"github.com/go-pkgz/auth/logger"
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
"github.com/go-pkgz/auth/avatar"
|
||||
"github.com/go-pkgz/auth/logger"
|
||||
"github.com/go-pkgz/auth/token"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/go-pkgz/rest"
|
||||
|
||||
"github.com/go-pkgz/auth/logger"
|
||||
|
||||
+9
-8
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ const (
|
||||
defaultTokenDuration = time.Minute * 15
|
||||
defaultCookieDuration = time.Hour * 24 * 31
|
||||
|
||||
tokenQuery = "token"
|
||||
defaultTokenQuery = "token"
|
||||
)
|
||||
|
||||
// Opts holds constructor params
|
||||
@@ -61,7 +61,7 @@ type Opts struct {
|
||||
JWTHeaderKey string
|
||||
XSRFCookieName string
|
||||
XSRFHeaderKey string
|
||||
|
||||
JWTQuery string
|
||||
AudienceReader Audience // allowed aud values
|
||||
Issuer string // optional value for iss claim, usually application name
|
||||
}
|
||||
@@ -80,6 +80,7 @@ func NewService(opts Opts) *Service {
|
||||
setDefault(&res.JWTHeaderKey, defaultJWTHeaderKey)
|
||||
setDefault(&res.XSRFCookieName, defaultXSRFCookieName)
|
||||
setDefault(&res.XSRFHeaderKey, defaultXSRFHeaderKey)
|
||||
setDefault(&res.JWTQuery, defaultTokenQuery)
|
||||
setDefault(&res.Issuer, defaultIssuer)
|
||||
|
||||
if opts.TokenDuration == 0 {
|
||||
@@ -167,12 +168,12 @@ func (j *Service) validate(claims *Claims) error {
|
||||
}
|
||||
|
||||
if e, ok := cerr.(*jwt.ValidationError); ok {
|
||||
e.Errors ^= jwt.ValidationErrorExpired // clear ValidationErrorExpired, allow expired token
|
||||
if e.Errors != 0 {
|
||||
return e
|
||||
if e.Errors == jwt.ValidationErrorExpired {
|
||||
return nil // allow expired tokens
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return cerr
|
||||
}
|
||||
|
||||
// Set creates token cookie with xsrf cookie and put it to ResponseWriter
|
||||
@@ -220,7 +221,7 @@ func (j *Service) Get(r *http.Request) (Claims, string, error) {
|
||||
tokenString := ""
|
||||
|
||||
// try to get from "token" query param
|
||||
if tkQuery := r.URL.Query().Get(tokenQuery); tkQuery != "" {
|
||||
if tkQuery := r.URL.Query().Get(j.JWTQuery); tkQuery != "" {
|
||||
tokenString = tkQuery
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user