Merge branch 'master' of https://github.com/piotrkochan/go-base into piotrkochan-master

This commit is contained in:
dhax 2019-01-14 21:30:32 +01:00
commit 6e627dd0a0
8 changed files with 35 additions and 29 deletions

View file

@ -5,7 +5,7 @@ import (
"time"
"github.com/dhax/go-base/auth/jwt"
"github.com/go-chi/jwtauth"
jwtgo "github.com/dgrijalva/jwt-go"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"github.com/go-pg/pg/orm"
@ -65,8 +65,8 @@ func (a *Account) CanLogin() bool {
}
// Claims returns the account's claims to be signed
func (a *Account) Claims() jwtauth.Claims {
return jwtauth.Claims{
func (a *Account) Claims() jwtgo.MapClaims {
return jwtgo.MapClaims{
"id": a.ID,
"sub": a.Name,
"roles": a.Roles,

View file

@ -16,8 +16,8 @@ import (
"github.com/go-chi/render"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"github.com/gofrs/uuid"
"github.com/mssola/user_agent"
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
)
@ -187,7 +187,7 @@ func (rs *Resource) token(w http.ResponseWriter, r *http.Request) {
browser, _ := ua.Browser()
token := &jwt.Token{
Token: uuid.NewV4().String(),
Token: uuid.Must(uuid.NewV4()).String(),
Expiry: time.Now().Add(rs.TokenAuth.JwtRefreshExpiry),
UpdatedAt: time.Now(),
AccountID: acc.ID,
@ -247,7 +247,7 @@ func (rs *Resource) refresh(w http.ResponseWriter, r *http.Request) {
return
}
token.Token = uuid.NewV4().String()
token.Token = uuid.Must(uuid.NewV4()).String()
token.Expiry = time.Now().Add(rs.TokenAuth.JwtRefreshExpiry)
token.UpdatedAt = time.Now()

View file

@ -14,8 +14,8 @@ import (
"testing"
"time"
jwtgo "github.com/dgrijalva/jwt-go"
"github.com/go-chi/chi"
"github.com/go-chi/jwtauth"
"github.com/spf13/viper"
"github.com/dhax/go-base/auth/jwt"
@ -240,7 +240,7 @@ func TestAuthResource_refresh(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
jwt := genJWT(jwtauth.Claims{"token": tc.token, "exp": time.Minute * tc.exp})
jwt := genJWT(jwtgo.MapClaims{"token": tc.token, "exp": time.Minute * tc.exp})
res, body := testRequest(t, ts, "POST", "/refresh", nil, jwt)
if res.StatusCode != tc.status {
t.Errorf("got http status %d, want: %d", res.StatusCode, tc.status)
@ -300,7 +300,7 @@ func TestAuthResource_logout(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
jwt := genJWT(jwtauth.Claims{"token": tc.token, "exp": time.Minute * tc.exp})
jwt := genJWT(jwtgo.MapClaims{"token": tc.token, "exp": time.Minute * tc.exp})
res, body := testRequest(t, ts, "POST", "/logout", nil, jwt)
if res.StatusCode != tc.status {
t.Errorf("got http status %d, want: %d", res.StatusCode, tc.status)
@ -343,7 +343,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io
return resp, string(respBody)
}
func genJWT(c jwtauth.Claims) string {
func genJWT(c jwtgo.MapClaims) string {
_, tokenString, _ := auth.TokenAuth.JwtAuth.Encode(c)
return tokenString
}