···
jwksCache cache.Cache[string, jwk.Key]
25
-
metadataCache cache.Cache[string, Metadata]
25
+
metadataCache cache.Cache[string, *Metadata]
type ManagerArgs struct {
···
jwksCache := cache.NewCache[string, jwk.Key]().WithLRU().WithMaxKeys(500).WithTTL(5 * time.Minute)
43
-
metadataCache := cache.NewCache[string, Metadata]().WithLRU().WithMaxKeys(500).WithTTL(5 * time.Minute)
43
+
metadataCache := cache.NewCache[string, *Metadata]().WithLRU().WithMaxKeys(500).WithTTL(5 * time.Minute)
···
60
-
if metadata.JWKS != nil && len(metadata.JWKS.Keys) > 0 {
61
-
// TODO: this is kinda bad but whatever for now. there could obviously be more than one jwk, and we need to
62
-
// make sure we use the right one
63
-
b, err := json.Marshal(metadata.JWKS.Keys[0])
60
+
if metadata.TokenEndpointAuthMethod == "private_key_jwt" {
61
+
if metadata.JWKS != nil && len(metadata.JWKS.Keys) > 0 {
62
+
// TODO: this is kinda bad but whatever for now. there could obviously be more than one jwk, and we need to
63
+
// make sure we use the right one
64
+
b, err := json.Marshal(metadata.JWKS.Keys[0])
68
-
k, err := helpers.ParseJWKFromBytes(b)
69
+
k, err := helpers.ParseJWKFromBytes(b)
74
-
} else if metadata.JWKSURI != nil {
75
-
maybeJwks, err := cm.getClientJwks(ctx, clientId, *metadata.JWKSURI)
75
+
} else if metadata.JWKS != nil {
76
+
} else if metadata.JWKSURI != nil {
77
+
maybeJwks, err := cm.getClientJwks(ctx, clientId, *metadata.JWKSURI)
82
-
return nil, fmt.Errorf("no valid jwks found in oauth client metadata")
84
+
return nil, fmt.Errorf("no valid jwks found in oauth client metadata")
···
func (cm *Manager) getClientMetadata(ctx context.Context, clientId string) (*Metadata, error) {
92
-
metadataCached, ok := cm.metadataCache.Get(clientId)
95
+
cached, ok := cm.metadataCache.Get(clientId)
req, err := http.NewRequestWithContext(ctx, "GET", clientId, nil)
···
123
+
cm.metadataCache.Set(clientId, validated, 10*time.Minute)
122
-
return &metadataCached, nil
···
return nil, fmt.Errorf("error unmarshaling metadata: %w", err)
212
+
if metadata.ClientURI == "" {
213
+
u, err := url.Parse(metadata.ClientID)
215
+
return nil, fmt.Errorf("unable to parse client id: %w", err)
219
+
metadata.ClientURI = u.String()
u, err := url.Parse(metadata.ClientURI)
return nil, fmt.Errorf("unable to parse client uri: %w", err)
227
+
if metadata.ClientName == "" {
228
+
metadata.ClientName = metadata.ClientURI
if isLocalHostname(u.Hostname()) {
213
-
return nil, errors.New("`client_uri` hostname is invalid")
232
+
return nil, fmt.Errorf("`client_uri` hostname is invalid: %s", u.Hostname())
if metadata.Scope == "" {
···
return nil, fmt.Errorf("loopback redirect uri %s must use http", ruri)
return nil, errors.New("only loopbvack redirect uris are allowed to use the `http` scheme")
case u.Scheme == "https":
if isLocalHostname(u.Hostname()) {
return nil, fmt.Errorf("redirect uri %s's domain must not be a local hostname", ruri)
case strings.Contains(u.Scheme, "."):
if metadata.ApplicationType != "native" {
return nil, errors.New("private-use uri scheme redirect uris are only allowed for native apps")