| 1 | // Copyright 2026 The frp Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package validation |
| 16 | |
| 17 | import ( |
| 18 | "errors" |
| 19 | "net/url" |
| 20 | "strings" |
| 21 | |
| 22 | v1 "github.com/fatedier/frp/pkg/config/v1" |
| 23 | ) |
| 24 | |
| 25 | func ValidateOIDCClientCredentialsConfig(c *v1.AuthOIDCClientConfig) error { |
| 26 | var errs []string |
| 27 | |
| 28 | if c.ClientID == "" { |
| 29 | errs = append(errs, "auth.oidc.clientID is required") |
| 30 | } |
| 31 | |
| 32 | if c.TokenEndpointURL == "" { |
| 33 | errs = append(errs, "auth.oidc.tokenEndpointURL is required") |
| 34 | } else { |
| 35 | tokenURL, err := url.Parse(c.TokenEndpointURL) |
| 36 | if err != nil || !tokenURL.IsAbs() || tokenURL.Host == "" { |
| 37 | errs = append(errs, "auth.oidc.tokenEndpointURL must be an absolute http or https URL") |
| 38 | } else if tokenURL.Scheme != "http" && tokenURL.Scheme != "https" { |
| 39 | errs = append(errs, "auth.oidc.tokenEndpointURL must use http or https") |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if _, ok := c.AdditionalEndpointParams["scope"]; ok { |
| 44 | errs = append(errs, "auth.oidc.additionalEndpointParams.scope is not allowed; use auth.oidc.scope instead") |
| 45 | } |
| 46 | |
| 47 | if c.Audience != "" { |
| 48 | if _, ok := c.AdditionalEndpointParams["audience"]; ok { |
| 49 | errs = append(errs, "cannot specify both auth.oidc.audience and auth.oidc.additionalEndpointParams.audience") |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if len(errs) == 0 { |
| 54 | return nil |
| 55 | } |
| 56 | return errors.New(strings.Join(errs, "; ")) |
| 57 | } |