mjwt/auth/refresh-token_test.go

26 lines
648 B
Go
Raw Normal View History

package auth
import (
2023-10-29 12:28:21 +00:00
"github.com/1f349/mjwt"
2024-07-27 19:25:56 +01:00
"github.com/golang-jwt/jwt/v4"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateRefreshToken(t *testing.T) {
2023-10-29 12:28:21 +00:00
t.Parallel()
kStore := mjwt.NewKeyStore()
2024-07-27 19:25:56 +01:00
s, err := mjwt.NewIssuerWithKeyStore("mjwt.test", "key1", jwt.SigningMethodRS512, kStore)
assert.NoError(t, err)
refreshToken, err := CreateRefreshToken(s, "1", "test", "test2", nil)
2024-06-09 20:40:13 +01:00
assert.NoError(t, err)
_, b, err := mjwt.ExtractClaims[RefreshTokenClaims](kStore, refreshToken)
2024-06-09 20:40:13 +01:00
assert.NoError(t, err)
assert.Equal(t, "1", b.Subject)
assert.Equal(t, "test", b.ID)
assert.Equal(t, "test2", b.Claims.AccessTokenId)
}