legacy.go 5.9 KB

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