From 0823d94fab3724a1e9a9675ce7cbba66a44be7b7 Mon Sep 17 00:00:00 2001 From: Guy Lewin Date: Mon, 24 Feb 2020 16:00:11 -0500 Subject: [PATCH] style: unexpose BaseAuth (into baseAuth) since its package-private --- models/auth/auth.go | 14 +++++++------- models/auth/oidc.go | 12 ++++++------ models/auth/token.go | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/models/auth/auth.go b/models/auth/auth.go index f7308c5e..941f0035 100644 --- a/models/auth/auth.go +++ b/models/auth/auth.go @@ -20,7 +20,7 @@ import ( "github.com/fatedier/frp/models/msg" ) -type BaseAuth struct { +type baseAuth struct { authenticateHeartBeats bool authenticateNewWorkConns bool } @@ -32,17 +32,17 @@ type Setter interface { } func NewAuthSetter(cfg config.ClientCommonConf) (authProvider Setter) { - baseAuth := BaseAuth{ + base := baseAuth{ authenticateHeartBeats: cfg.AuthenticateHeartBeats, authenticateNewWorkConns: cfg.AuthenticateNewWorkConns, } switch cfg.AuthenticationMethod { case consts.TokenAuthMethod: - authProvider = NewTokenAuth(baseAuth, cfg.Token) + authProvider = NewTokenAuth(base, cfg.Token) case consts.OidcAuthMethod: authProvider = NewOidcAuthSetter( - baseAuth, + base, cfg.OidcClientId, cfg.OidcClientSecret, cfg.OidcAudience, @@ -60,17 +60,17 @@ type Verifier interface { } func NewAuthVerifier(cfg config.ServerCommonConf) (authVerifier Verifier) { - baseAuth := BaseAuth{ + base := baseAuth{ authenticateHeartBeats: cfg.AuthenticateHeartBeats, authenticateNewWorkConns: cfg.AuthenticateNewWorkConns, } switch cfg.AuthenticationMethod { case consts.TokenAuthMethod: - authVerifier = NewTokenAuth(baseAuth, cfg.Token) + authVerifier = NewTokenAuth(base, cfg.Token) case consts.OidcAuthMethod: authVerifier = NewOidcAuthVerifier( - baseAuth, + base, cfg.OidcIssuer, cfg.OidcAudience, cfg.OidcSkipExpiryCheck, diff --git a/models/auth/oidc.go b/models/auth/oidc.go index 651fe8f1..f662b4c2 100644 --- a/models/auth/oidc.go +++ b/models/auth/oidc.go @@ -25,12 +25,12 @@ import ( ) type OidcAuthProvider struct { - BaseAuth + baseAuth 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{ ClientID: clientId, ClientSecret: clientSecret, @@ -39,7 +39,7 @@ func NewOidcAuthSetter(baseAuth BaseAuth, clientId string, clientSecret string, } return &OidcAuthProvider{ - BaseAuth: baseAuth, + baseAuth: base, tokenGenerator: tokenGenerator, } } @@ -76,13 +76,13 @@ func (auth *OidcAuthProvider) SetNewWorkConn(newWorkConnMsg *msg.NewWorkConn) (e } type OidcAuthConsumer struct { - BaseAuth + baseAuth verifier *oidc.IDTokenVerifier 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) if err != nil { panic(err) @@ -94,7 +94,7 @@ func NewOidcAuthVerifier(baseAuth BaseAuth, issuer string, audience string, skip SkipIssuerCheck: skipIssuerCheck, } return &OidcAuthConsumer{ - BaseAuth: baseAuth, + baseAuth: base, verifier: provider.Verifier(&verifierConf), } } diff --git a/models/auth/token.go b/models/auth/token.go index c1d494f7..3cdc704e 100644 --- a/models/auth/token.go +++ b/models/auth/token.go @@ -22,14 +22,14 @@ import ( ) type TokenAuthSetterVerifier struct { - BaseAuth + baseAuth token string } -func NewTokenAuth(baseAuth BaseAuth, token string) *TokenAuthSetterVerifier { +func NewTokenAuth(base baseAuth, token string) *TokenAuthSetterVerifier { return &TokenAuthSetterVerifier{ - BaseAuth: baseAuth, + baseAuth: base, token: token, } }