[authz]: use authlib client (#91205)

authz: use authlib client

Co-authored-by: Gabriel MABILLE <gabriel.mabille@grafana.com>
This commit is contained in:
Claudiu Dragalina-Paraipan
2024-07-30 17:49:46 +03:00
committed by GitHub
co-authored by Gabriel MABILLE
parent bee678da94
commit 05ab4cdd1f
5 changed files with 115 additions and 42 deletions
+20 -4
View File
@@ -10,7 +10,7 @@ type Mode string
func (s Mode) IsValid() bool {
switch s {
case ModeGRPC, ModeInProc:
case ModeGRPC, ModeInProc, ModeCloud:
return true
}
return false
@@ -19,12 +19,17 @@ func (s Mode) IsValid() bool {
const (
ModeGRPC Mode = "grpc"
ModeInProc Mode = "inproc"
ModeCloud Mode = "cloud"
)
type Cfg struct {
remoteAddress string
listen bool
mode Mode
token string
tokenExchangeURL string
tokenNamespace string
}
func ReadCfg(cfg *setting.Cfg) (*Cfg, error) {
@@ -35,9 +40,20 @@ func ReadCfg(cfg *setting.Cfg) (*Cfg, error) {
return nil, fmt.Errorf("authorization: invalid mode %q", mode)
}
token := section.Key("token").MustString("")
tokenExchangeURL := section.Key("token_exchange_url").MustString("")
tokenNamespace := section.Key("token_namespace").MustString("stack-" + cfg.StackID)
if mode == ModeCloud && token == "" && tokenExchangeURL == "" {
return nil, fmt.Errorf("authorization: missing token or tokenExchangeUrl")
}
return &Cfg{
remoteAddress: section.Key("remote_address").MustString(""),
listen: section.Key("listen").MustBool(false),
mode: mode,
remoteAddress: section.Key("remote_address").MustString(""),
listen: section.Key("listen").MustBool(false),
mode: mode,
token: token,
tokenExchangeURL: tokenExchangeURL,
tokenNamespace: tokenNamespace,
}, nil
}