style: unexpose BaseAuth (into baseAuth) since its package-private

This commit is contained in:
Guy Lewin 2020-02-24 16:00:11 -05:00
parent be8db5feb7
commit 0823d94fab
3 changed files with 16 additions and 16 deletions

View File

@ -20,7 +20,7 @@ import (
"github.com/fatedier/frp/models/msg" "github.com/fatedier/frp/models/msg"
) )
type BaseAuth struct { type baseAuth struct {
authenticateHeartBeats bool authenticateHeartBeats bool
authenticateNewWorkConns bool authenticateNewWorkConns bool
} }
@ -32,17 +32,17 @@ type Setter interface {
} }
func NewAuthSetter(cfg config.ClientCommonConf) (authProvider Setter) { func NewAuthSetter(cfg config.ClientCommonConf) (authProvider Setter) {
baseAuth := BaseAuth{ base := baseAuth{
authenticateHeartBeats: cfg.AuthenticateHeartBeats, authenticateHeartBeats: cfg.AuthenticateHeartBeats,
authenticateNewWorkConns: cfg.AuthenticateNewWorkConns, authenticateNewWorkConns: cfg.AuthenticateNewWorkConns,
} }
switch cfg.AuthenticationMethod { switch cfg.AuthenticationMethod {
case consts.TokenAuthMethod: case consts.TokenAuthMethod:
authProvider = NewTokenAuth(baseAuth, cfg.Token) authProvider = NewTokenAuth(base, cfg.Token)
case consts.OidcAuthMethod: case consts.OidcAuthMethod:
authProvider = NewOidcAuthSetter( authProvider = NewOidcAuthSetter(
baseAuth, base,
cfg.OidcClientId, cfg.OidcClientId,
cfg.OidcClientSecret, cfg.OidcClientSecret,
cfg.OidcAudience, cfg.OidcAudience,
@ -60,17 +60,17 @@ type Verifier interface {
} }
func NewAuthVerifier(cfg config.ServerCommonConf) (authVerifier Verifier) { func NewAuthVerifier(cfg config.ServerCommonConf) (authVerifier Verifier) {
baseAuth := BaseAuth{ base := baseAuth{
authenticateHeartBeats: cfg.AuthenticateHeartBeats, authenticateHeartBeats: cfg.AuthenticateHeartBeats,
authenticateNewWorkConns: cfg.AuthenticateNewWorkConns, authenticateNewWorkConns: cfg.AuthenticateNewWorkConns,
} }
switch cfg.AuthenticationMethod { switch cfg.AuthenticationMethod {
case consts.TokenAuthMethod: case consts.TokenAuthMethod:
authVerifier = NewTokenAuth(baseAuth, cfg.Token) authVerifier = NewTokenAuth(base, cfg.Token)
case consts.OidcAuthMethod: case consts.OidcAuthMethod:
authVerifier = NewOidcAuthVerifier( authVerifier = NewOidcAuthVerifier(
baseAuth, base,
cfg.OidcIssuer, cfg.OidcIssuer,
cfg.OidcAudience, cfg.OidcAudience,
cfg.OidcSkipExpiryCheck, cfg.OidcSkipExpiryCheck,

View File

@ -25,12 +25,12 @@ import (
) )
type OidcAuthProvider struct { type OidcAuthProvider struct {
BaseAuth baseAuth
tokenGenerator *clientcredentials.Config tokenGenerator *clientcredentials.Config
} }
func NewOidcAuthSetter(baseAuth BaseAuth, clientId string, clientSecret string, audience string, tokenEndpointUrl string) *OidcAuthProvider { func NewOidcAuthSetter(base baseAuth, clientId string, clientSecret string, audience string, tokenEndpointUrl string) *OidcAuthProvider {
tokenGenerator := &clientcredentials.Config{ tokenGenerator := &clientcredentials.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
@ -39,7 +39,7 @@ func NewOidcAuthSetter(baseAuth BaseAuth, clientId string, clientSecret string,
} }
return &OidcAuthProvider{ return &OidcAuthProvider{
BaseAuth: baseAuth, baseAuth: base,
tokenGenerator: tokenGenerator, tokenGenerator: tokenGenerator,
} }
} }
@ -76,13 +76,13 @@ func (auth *OidcAuthProvider) SetNewWorkConn(newWorkConnMsg *msg.NewWorkConn) (e
} }
type OidcAuthConsumer struct { type OidcAuthConsumer struct {
BaseAuth baseAuth
verifier *oidc.IDTokenVerifier verifier *oidc.IDTokenVerifier
subjectFromLogin string subjectFromLogin string
} }
func NewOidcAuthVerifier(baseAuth BaseAuth, issuer string, audience string, skipExpiryCheck bool, skipIssuerCheck bool) *OidcAuthConsumer { func NewOidcAuthVerifier(base baseAuth, issuer string, audience string, skipExpiryCheck bool, skipIssuerCheck bool) *OidcAuthConsumer {
provider, err := oidc.NewProvider(context.Background(), issuer) provider, err := oidc.NewProvider(context.Background(), issuer)
if err != nil { if err != nil {
panic(err) panic(err)
@ -94,7 +94,7 @@ func NewOidcAuthVerifier(baseAuth BaseAuth, issuer string, audience string, skip
SkipIssuerCheck: skipIssuerCheck, SkipIssuerCheck: skipIssuerCheck,
} }
return &OidcAuthConsumer{ return &OidcAuthConsumer{
BaseAuth: baseAuth, baseAuth: base,
verifier: provider.Verifier(&verifierConf), verifier: provider.Verifier(&verifierConf),
} }
} }

View File

@ -22,14 +22,14 @@ import (
) )
type TokenAuthSetterVerifier struct { type TokenAuthSetterVerifier struct {
BaseAuth baseAuth
token string token string
} }
func NewTokenAuth(baseAuth BaseAuth, token string) *TokenAuthSetterVerifier { func NewTokenAuth(base baseAuth, token string) *TokenAuthSetterVerifier {
return &TokenAuthSetterVerifier{ return &TokenAuthSetterVerifier{
BaseAuth: baseAuth, baseAuth: base,
token: token, token: token,
} }
} }