forked from kyma-project/kyma
/
oidc.go
38 lines (34 loc) · 1.14 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
package authn
import (
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
"k8s.io/apiserver/plugin/pkg/authenticator/token/oidc"
)
// OIDCConfig represents configuration used for JWT request authentication
type OIDCConfig struct {
IssuerURL string
ClientID string
CAFile string
UsernameClaim string
UsernamePrefix string
GroupsClaim string
GroupsPrefix string
SupportedSigningAlgs []string
}
// NewOIDCAuthenticator returns OIDC authenticator
func NewOIDCAuthenticator(config *OIDCConfig) (authenticator.Request, error) {
tokenAuthenticator, err := oidc.New(oidc.Options{
IssuerURL: config.IssuerURL,
ClientID: config.ClientID,
CAFile: config.CAFile,
UsernameClaim: config.UsernameClaim,
UsernamePrefix: config.UsernamePrefix,
GroupsClaim: config.GroupsClaim,
GroupsPrefix: config.GroupsPrefix,
SupportedSigningAlgs: config.SupportedSigningAlgs,
})
if err != nil {
return nil, err
}
return bearertoken.New(tokenAuthenticator), nil
}