Seperate JWT refresh / access tokens

This commit is contained in:
Ben Toogood 2020-05-14 13:56:51 +01:00
parent f549e20fa2
commit 16af265e8b

View File

@ -2,6 +2,7 @@ package jwt
import ( import (
"sync" "sync"
"time"
"github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/auth/token"
@ -176,15 +177,20 @@ func (j *jwt) Token(opts ...auth.TokenOption) (*auth.Token, error) {
return nil, err return nil, err
} }
tok, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry)) access, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry))
if err != nil {
return nil, err
}
refresh, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry+time.Hour))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &auth.Token{ return &auth.Token{
Created: tok.Created, Created: access.Created,
Expiry: tok.Expiry, Expiry: access.Expiry,
AccessToken: tok.Token, AccessToken: access.Token,
RefreshToken: tok.Token, RefreshToken: refresh.Token,
}, nil }, nil
} }