| // |
| 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 legacy |
| 16 |
| 17 | type BaseConfig struct { |
| 18 | // AuthenticationMethod specifies what authentication method to use to |
| 19 | // authenticate frpc with frps. If "token" is specified - token will be |
| 20 | // read into login message. If "oidc" is specified - OIDC (Open ID Connect) |
| 21 | // token will be issued using OIDC settings. By default, this value is "token". |
| 22 | AuthenticationMethod string `ini:"authentication_method" json:"authentication_method"` |
| 23 | // AuthenticateHeartBeats specifies whether to include authentication token in |
| 24 | // heartbeats sent to frps. By default, this value is false. |
| 25 | AuthenticateHeartBeats bool `ini:"authenticate_heartbeats" json:"authenticate_heartbeats"` |
| 26 | // AuthenticateNewWorkConns specifies whether to include authentication token in |
| 27 | // new work connections sent to frps. By default, this value is false. |
| 28 | AuthenticateNewWorkConns bool `ini:"authenticate_new_work_conns" json:"authenticate_new_work_conns"` |
| 29 | } |
| 30 |
| 31 | func getDefaultBaseConf() BaseConfig { |
| 32 | return BaseConfig{ |
| 33 | AuthenticationMethod: "token", |
| 34 | AuthenticateHeartBeats: false, |
| 35 | AuthenticateNewWorkConns: false, |
| 36 | } |
| 37 | } |
| 38 |
| 39 | type ClientConfig struct { |
| 40 | BaseConfig `ini:",extends"` |
| 41 | OidcClientConfig `ini:",extends"` |
| 42 | TokenConfig `ini:",extends"` |
| 43 | } |
| 44 |
| 45 | func GetDefaultClientConf() ClientConfig { |
| 46 | return ClientConfig{ |
| 47 | BaseConfig: getDefaultBaseConf(), |
| 48 | OidcClientConfig: getDefaultOidcClientConf(), |
| 49 | TokenConfig: getDefaultTokenConf(), |
| 50 | } |
| 51 | } |
| 52 |
| 53 | type ServerConfig struct { |
| 54 | BaseConfig `ini:",extends"` |
| 55 | OidcServerConfig `ini:",extends"` |
| 56 | TokenConfig `ini:",extends"` |
| 57 | } |
| 58 |
| 59 | func GetDefaultServerConf() ServerConfig { |
| 60 | return ServerConfig{ |
| 61 | BaseConfig: getDefaultBaseConf(), |
| 62 | OidcServerConfig: getDefaultOidcServerConf(), |
| 63 | TokenConfig: getDefaultTokenConf(), |
| 64 | } |
| 65 | } |
| 66 |
| 67 | type OidcClientConfig struct { |
| 68 | // OidcClientID specifies the client ID to use to get a token in OIDC |
| 69 | // authentication if AuthenticationMethod == "oidc". By default, this value |
| 70 | // is "". |
| 71 | OidcClientID string `ini:"oidc_client_id" json:"oidc_client_id"` |
| 72 | // OidcClientSecret specifies the client secret to use to get a token in OIDC |
| 73 | // authentication if AuthenticationMethod == "oidc". By default, this value |
| 74 | // is "". |
| 75 | OidcClientSecret string `ini:"oidc_client_secret" json:"oidc_client_secret"` |
| 76 | // OidcAudience specifies the audience of the token in OIDC authentication |
| 77 | // if AuthenticationMethod == "oidc". By default, this value is "". |
| 78 | OidcAudience string `ini:"oidc_audience" json:"oidc_audience"` |
| 79 | // OidcScope specifies the scope of the token in OIDC authentication |
| 80 | // if AuthenticationMethod == "oidc". By default, this value is "". |
| 81 | OidcScope string `ini:"oidc_scope" json:"oidc_scope"` |
| 82 | // OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint. |
| 83 | // It will be used to get an OIDC token if AuthenticationMethod == "oidc". |
| 84 | // By default, this value is "". |
| 85 | OidcTokenEndpointURL string `ini:"oidc_token_endpoint_url" json:"oidc_token_endpoint_url"` |
| 86 |
| 87 | // OidcAdditionalEndpointParams specifies additional parameters to be sent |
| 88 | // this field will be transfer to map[string][]string in OIDC token generator |
| 89 | // The field will be set by prefix "oidc_additional_" |
| 90 | OidcAdditionalEndpointParams map[string]string `ini:"-" json:"oidc_additional_endpoint_params"` |
| 91 | } |
| 92 |
| 93 | func getDefaultOidcClientConf() OidcClientConfig { |
| 94 | return OidcClientConfig{ |
| 95 | OidcClientID: "", |
| 96 | OidcClientSecret: "", |
| 97 | OidcAudience: "", |
| 98 | OidcScope: "", |
| 99 | OidcTokenEndpointURL: "", |
| 100 | OidcAdditionalEndpointParams: make(map[string]string), |
| 101 | } |
| 102 | } |
| 103 |
| 104 | type OidcServerConfig struct { |
| 105 | // OidcIssuer specifies the issuer to verify OIDC tokens with. This issuer |
| 106 | // will be used to load public keys to verify signature and will be compared |
| 107 | // with the issuer claim in the OIDC token. It will be used if |
| 108 | // AuthenticationMethod == "oidc". By default, this value is "". |
| 109 | OidcIssuer string `ini:"oidc_issuer" json:"oidc_issuer"` |
| 110 | // OidcAudience specifies the audience OIDC tokens should contain when validated. |
| 111 | // If this value is empty, audience ("client ID") verification will be skipped. |
| 112 | // It will be used when AuthenticationMethod == "oidc". By default, this |
| 113 | // value is "". |
| 114 | OidcAudience string `ini:"oidc_audience" json:"oidc_audience"` |
| 115 | // OidcSkipExpiryCheck specifies whether to skip checking if the OIDC token is |
| 116 | // expired. It will be used when AuthenticationMethod == "oidc". By default, this |
| 117 | // value is false. |
| 118 | OidcSkipExpiryCheck bool `ini:"oidc_skip_expiry_check" json:"oidc_skip_expiry_check"` |
| 119 | // OidcSkipIssuerCheck specifies whether to skip checking if the OIDC token's |
| 120 | // issuer claim matches the issuer specified in OidcIssuer. It will be used when |
| 121 | // AuthenticationMethod == "oidc". By default, this value is false. |
| 122 | OidcSkipIssuerCheck bool `ini:"oidc_skip_issuer_check" json:"oidc_skip_issuer_check"` |
| 123 | } |
| 124 |
| 125 | func getDefaultOidcServerConf() OidcServerConfig { |
| 126 | return OidcServerConfig{ |
| 127 | OidcIssuer: "", |
| 128 | OidcAudience: "", |
| 129 | OidcSkipExpiryCheck: false, |
| 130 | OidcSkipIssuerCheck: false, |
| 131 | } |
| 132 | } |
| 133 |
| 134 | type TokenConfig struct { |
| 135 | // Token specifies the authorization token used to create keys to be sent |
| 136 | // to the server. The server must have a matching token for authorization |
| 137 | // to succeed. By default, this value is "". |
| 138 | Token string `ini:"token" json:"token"` |
| 139 | } |
| 140 |
| 141 | func getDefaultTokenConf() TokenConfig { |
| 142 | return TokenConfig{ |
| 143 | Token: "", |
| 144 | } |
| 145 | } |