Authn: Sync authlib and update how we construct authn client interceptor (#101124)
* Sync authlib and update how we construct authn client interceptor * Remove namespace from checker
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package grpcutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-jose/go-jose/v3/jwt"
|
||||
"github.com/grafana/authlib/authn"
|
||||
@@ -12,29 +10,21 @@ import (
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
)
|
||||
|
||||
type inProcExchanger struct {
|
||||
tokenResponse *authn.TokenExchangeResponse
|
||||
}
|
||||
|
||||
func ProvideInProcExchanger() *inProcExchanger {
|
||||
tokenResponse, err := createInProcToken()
|
||||
func ProvideInProcExchanger() authn.StaticTokenExchanger {
|
||||
token, err := createInProcToken()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &inProcExchanger{tokenResponse}
|
||||
return authn.NewStaticTokenExchanger(token)
|
||||
}
|
||||
|
||||
func (e *inProcExchanger) Exchange(ctx context.Context, r authn.TokenExchangeRequest) (*authn.TokenExchangeResponse, error) {
|
||||
return e.tokenResponse, nil
|
||||
}
|
||||
|
||||
func createInProcToken() (*authn.TokenExchangeResponse, error) {
|
||||
func createInProcToken() (string, error) {
|
||||
claims := authn.Claims[authn.AccessTokenClaims]{
|
||||
Claims: jwt.Claims{
|
||||
Audience: []string{"resourceStore"},
|
||||
Issuer: "grafana",
|
||||
Subject: types.NewTypeID(types.TypeAccessPolicy, "grafana"),
|
||||
Audience: []string{"resourceStore"},
|
||||
},
|
||||
Rest: authn.AccessTokenClaims{
|
||||
Namespace: "*",
|
||||
@@ -48,15 +38,13 @@ func createInProcToken() (*authn.TokenExchangeResponse, error) {
|
||||
"typ": authn.TokenTypeAccess,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return &authn.TokenExchangeResponse{
|
||||
Token: fmt.Sprintf("%s.%s.", base64.RawURLEncoding.EncodeToString(header), base64.RawURLEncoding.EncodeToString(payload)),
|
||||
}, nil
|
||||
return base64.RawURLEncoding.EncodeToString(header) + "." + base64.RawURLEncoding.EncodeToString(payload) + ".", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user