1
0

auth.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 guylewin, guy@lewin.co.il
  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 auth
  15. import (
  16. "fmt"
  17. v1 "github.com/fatedier/frp/pkg/config/v1"
  18. "github.com/fatedier/frp/pkg/consts"
  19. "github.com/fatedier/frp/pkg/msg"
  20. )
  21. type Setter interface {
  22. SetLogin(*msg.Login) error
  23. SetPing(*msg.Ping) error
  24. SetNewWorkConn(*msg.NewWorkConn) error
  25. }
  26. func NewAuthSetter(cfg v1.AuthClientConfig) (authProvider Setter) {
  27. switch cfg.Method {
  28. case consts.TokenAuthMethod:
  29. authProvider = NewTokenAuth(cfg.AdditionalScopes, cfg.Token)
  30. case consts.OidcAuthMethod:
  31. authProvider = NewOidcAuthSetter(cfg.AdditionalScopes, cfg.OIDC)
  32. default:
  33. panic(fmt.Sprintf("wrong method: '%s'", cfg.Method))
  34. }
  35. return authProvider
  36. }
  37. type Verifier interface {
  38. VerifyLogin(*msg.Login) error
  39. VerifyPing(*msg.Ping) error
  40. VerifyNewWorkConn(*msg.NewWorkConn) error
  41. }
  42. func NewAuthVerifier(cfg v1.AuthServerConfig) (authVerifier Verifier) {
  43. switch cfg.Method {
  44. case consts.TokenAuthMethod:
  45. authVerifier = NewTokenAuth(cfg.AdditionalScopes, cfg.Token)
  46. case consts.OidcAuthMethod:
  47. authVerifier = NewOidcAuthVerifier(cfg.AdditionalScopes, cfg.OIDC)
  48. }
  49. return authVerifier
  50. }