[auth] make id-token optional (#97831)

make idtoken optional

enure there is always an identity in the context

fix: update token

fix: now it should work

fix: now it should work
This commit is contained in:
Georges Chaudy
2024-12-17 13:28:00 +02:00
committed by GitHub
parent 02fec7c4ad
commit 3fe2227c82
4 changed files with 32 additions and 71 deletions
@@ -0,0 +1,27 @@
package resource
import (
"context"
"testing"
"github.com/grafana/authlib/claims"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/stretchr/testify/assert"
)
func TestIDTokenExtractor(t *testing.T) {
t.Run("should return an error when no claims found", func(t *testing.T) {
token, err := idTokenExtractor(context.Background())
assert.Error(t, err)
assert.Empty(t, token)
})
t.Run("should return an empty token for static requester of type service account as grafana admin ", func(t *testing.T) {
ctx := identity.WithRequester(context.Background(), &identity.StaticRequester{
Type: claims.TypeServiceAccount,
IsGrafanaAdmin: true,
})
token, err := idTokenExtractor(ctx)
assert.NoError(t, err)
assert.Empty(t, token)
})
}