Chore: Update authlib (#110880)

* Chore: Update authlib

* exclude incompatible version of github.com/grafana/gomemcache

* Update go-jose to v4

* fix jose imports

* remove jose v3 from go.mod

* fix tests

* fix serialize

* fix failing live tests

* add v1 of ES256 testkeys. Port tests to use ES256 instead of HS256

* accept more signature algs for okta and azuread

* azure social graph token sig

* accept more signature algs for oauth refresh and jwt auth

* update workspace

* add a static signer for inproc

* rebase and fix ext_jwt

* fix jwt tests

* apply alex patch on gomemcache

* update linting

* fix ext_jwt panic

* update workspaces

---------

Co-authored-by: Jo Garnier <git@jguer.space>
This commit is contained in:
Alexander Zobnin
2025-09-15 12:45:15 +02:00
committed by GitHub
co-authored by Jo Garnier
parent 172febd690
commit 294fd943c0
62 changed files with 470 additions and 383 deletions
+26 -14
View File
@@ -2,16 +2,18 @@ package resource
import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"github.com/fullstorydev/grpchan"
"github.com/fullstorydev/grpchan/inprocgrpc"
"github.com/go-jose/go-jose/v3/jwt"
"github.com/go-jose/go-jose/v4"
"github.com/go-jose/go-jose/v4/jwt"
grpcAuth "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
@@ -192,6 +194,23 @@ func ProvideInProcExchanger() authnlib.StaticTokenExchanger {
}
func createInProcToken() (string, error) {
// Generate ES256 private key
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return "", fmt.Errorf("failed to generate ES256 private key: %w", err)
}
// Create signer with ES256 algorithm
signer, err := jose.NewSigner(jose.SigningKey{Algorithm: jose.ES256, Key: privateKey}, &jose.SignerOptions{
ExtraHeaders: map[jose.HeaderKey]interface{}{
jose.HeaderKey("typ"): authnlib.TokenTypeAccess,
},
})
if err != nil {
return "", fmt.Errorf("failed to create signer: %w", err)
}
// Create claims
claims := authnlib.Claims[authnlib.AccessTokenClaims]{
Claims: jwt.Claims{
Issuer: "grafana",
@@ -205,18 +224,11 @@ func createInProcToken() (string, error) {
},
}
header, err := json.Marshal(map[string]string{
"alg": "none",
"typ": authnlib.TokenTypeAccess,
})
// Sign and create the JWT
token, err := jwt.Signed(signer).Claims(claims).Serialize()
if err != nil {
return "", err
return "", fmt.Errorf("failed to sign JWT: %w", err)
}
payload, err := json.Marshal(claims)
if err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(header) + "." + base64.RawURLEncoding.EncodeToString(payload) + ".", nil
return token, nil
}