This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
oidc.go
64 lines (55 loc) · 1.84 KB
/
oidc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package auth
import (
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/reconciling/auth"
helper2 "github.com/caos/orbos/internal/utils/helper"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
)
type oidc struct {
Name string `yaml:"name,omitempty"`
Issuer string `yaml:"issuer,omitempty"`
ClientID string `yaml:"clientID,omitempty"`
ClientSecret string `yaml:"clientSecret,omitempty"`
RequestedScopes []string `yaml:"requestedScopes,omitempty"`
RequestedIDTokenClaims map[string]*Claim `yaml:"requestedIDTokenClaims,omitempty"`
}
type Claim struct {
Essential bool `yaml:"essential,omitempty"`
Values []string `yaml:"values,omitempty"`
}
func GetOIDC(spec *auth.Auth) (string, error) {
if spec == nil || spec.OIDC == nil {
return "", nil
}
clientID, err := helper2.GetSecretValue(spec.OIDC.ClientID, spec.OIDC.ExistingClientIDSecret)
if err != nil {
return "", err
}
clientSecret, err := helper2.GetSecretValue(spec.OIDC.ClientSecret, spec.OIDC.ExistingClientSecretSecret)
if err != nil {
return "", err
}
if clientID == "" || clientSecret == "" {
return "", nil
}
var claims map[string]*Claim
if len(spec.OIDC.RequestedIDTokenClaims) > 0 {
claims = make(map[string]*Claim, 0)
for k, v := range spec.OIDC.RequestedIDTokenClaims {
claims[k] = &Claim{
Essential: v.Essential,
Values: v.Values,
}
}
}
oidc := &oidc{
Name: spec.OIDC.Name,
Issuer: spec.OIDC.Issuer,
ClientID: clientID,
ClientSecret: clientSecret,
RequestedScopes: spec.OIDC.RequestedScopes,
RequestedIDTokenClaims: claims,
}
data, err := yaml.Marshal(oidc)
return string(data), errors.Wrap(err, "Error while generating argocd oidc configuration")
}