From 7c63be6c8d76828d1db7683fdfaaed97f7580cc7 Mon Sep 17 00:00:00 2001 From: corbadovych <149707852+corbadovych@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:20:59 +0200 Subject: [PATCH] jwks lazy init (#10) --- pkg/sdk/session/session.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/sdk/session/session.go b/pkg/sdk/session/session.go index 3116259..fb86310 100644 --- a/pkg/sdk/session/session.go +++ b/pkg/sdk/session/session.go @@ -37,15 +37,9 @@ func New(client *api.ClientWithResponses, config *config.Config) (*Impl, error) return nil, err } - jwks, err := newJWKS(config) - if err != nil { - return nil, err - } - return &Impl{ client: client, config: config, - jwks: jwks, }, nil } @@ -92,6 +86,15 @@ func (i *Impl) ValidateShortSessionValue(shortSession string) (*entity.User, err return nil, nil } + if i.jwks == nil { + jwks, err := newJWKS(i.config) + if err != nil { + return nil, err + } + + i.jwks = jwks + } + token, err := jwt.ParseWithClaims(shortSession, &entity.Claims{}, i.jwks.Keyfunc) if err != nil { return nil, errors.WithStack(err)