1
0

auth.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. authVerifier = NewOidcAuthVerifier(cfg.AdditionalScopes, cfg.OIDC)
  47. }
  48. return authVerifier
  49. }