mirror of https://github.com/grafana/grafana
Co-Authored-By: Gabriel MABILLE <gamab@users.noreply.github.com>pull/91665/head
parent
2e2ddc5c42
commit
92aba937a9
@ -0,0 +1,21 @@ |
|||||||
|
package grpcutils |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/grafana/grafana/pkg/setting" |
||||||
|
) |
||||||
|
|
||||||
|
type GrpcClientConfig struct { |
||||||
|
Token string |
||||||
|
TokenExchangeURL string |
||||||
|
TokenNamespace string |
||||||
|
} |
||||||
|
|
||||||
|
func ReadCfg(cfg *setting.Cfg) *GrpcClientConfig { |
||||||
|
section := cfg.SectionWithEnvOverrides("grpc_client_authentication") |
||||||
|
|
||||||
|
return &GrpcClientConfig{ |
||||||
|
Token: section.Key("token").MustString(""), |
||||||
|
TokenExchangeURL: section.Key("token_exchange_url").MustString(""), |
||||||
|
TokenNamespace: section.Key("token_namespace").MustString("stack-" + cfg.StackID), |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package grpc |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
|
||||||
|
authnlib "github.com/grafana/authlib/authn" |
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/apimachinery/identity" |
||||||
|
) |
||||||
|
|
||||||
|
type InProcAuthenticator struct{} |
||||||
|
|
||||||
|
func (f *InProcAuthenticator) Authenticate(ctx context.Context) (context.Context, error) { |
||||||
|
r, err := identity.GetRequester(ctx) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
idClaims := r.GetIDClaims() |
||||||
|
if idClaims == nil { |
||||||
|
return nil, fmt.Errorf("no id claims found") |
||||||
|
} |
||||||
|
|
||||||
|
callerAuthInfo := authnlib.CallerAuthInfo{IDTokenClaims: idClaims} |
||||||
|
return authnlib.AddCallerAuthInfoToContext(ctx, callerAuthInfo), nil |
||||||
|
} |
||||||
Loading…
Reference in new issue