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/msg"
  19. )
  20. type Setter interface {
  21. SetLogin(*msg.Login) error
  22. SetPing(*msg.Ping) error
  23. SetNewWorkConn(*msg.NewWorkConn) error
  24. }
  25. func NewAuthSetter(cfg v1.AuthClientConfig) (authProvider Setter) {
  26. switch cfg.Method {
  27. case v1.AuthMethodToken:
  28. authProvider = NewTokenAuth(cfg.AdditionalScopes, cfg.Token)
  29. case v1.AuthMethodOIDC:
  30. authProvider = NewOidcAuthSetter(cfg.AdditionalScopes, cfg.OIDC)
  31. default:
  32. panic(fmt.Sprintf("wrong method: '%s'", cfg.Method))
  33. }
  34. return authProvider
  35. }
  36. type Verifier interface {
  37. VerifyLogin(*msg.Login) error
  38. VerifyPing(*msg.Ping) error
  39. VerifyNewWorkConn(*msg.NewWorkConn) error
  40. }
  41. func NewAuthVerifier(cfg v1.AuthServerConfig) (authVerifier Verifier) {
  42. switch cfg.Method {
  43. case v1.AuthMethodToken:
  44. authVerifier = NewTokenAuth(cfg.AdditionalScopes, cfg.Token)
  45. case v1.AuthMethodOIDC:
  46. tokenVerifier := NewTokenVerifier(cfg.OIDC)
  47. authVerifier = NewOidcAuthVerifier(cfg.AdditionalScopes, tokenVerifier)
  48. }
  49. return authVerifier
  50. }